It is currently February 19th, 2020, 2:48 pm

Getting 'Update' Value

Discuss the use of Lua in Script measures.
User avatar
Socks the Fox
Posts: 99
Joined: August 25th, 2015, 6:40 pm

Getting 'Update' Value

Post by Socks the Fox »

I'm just about ready to release an update to my Chameleon demo skin, which now uses a lua script to do some basic cross-fading. I'd really like for it to grab the update rate for the overall skin programmatically instead of currently assuming a 25ms timestep, but can't figure out how.

Alternatively, it'd be okay to be able to get the current timestamp in ms, which could be used to figure out the actual time between updates with some basic math, but I can't find how to do that without creating another measure and is a bit overkill anyway.
Author of Chameleon :: Like my plugin? Consider donating! I don't need much :3
User avatar
jsmorley
Developer
Posts: 20250
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting 'Update' Value

Post by jsmorley »

Socks the Fox wrote:I'm just about ready to release an update to my Chameleon demo skin, which now uses a lua script to do some basic cross-fading. I'd really like for it to grab the update rate for the overall skin programmatically instead of currently assuming a 25ms timestep, but can't figure out how.

Alternatively, it'd be okay to be able to get the current timestamp in ms, which could be used to figure out the actual time between updates with some basic math, but I can't find how to do that without creating another measure and is a bit overkill anyway.
There really is no good way to do that. The skin does not expose its own Update value in any way you can get at in Lua, and you can't even depend on reading the skin itself, as it could be encoded as UTF-16 which Lua can't read. I think the best bet it just have the Update rate of the skin hard-coded as an option on the Lua Script measure.

[MeasureScript]
Measure=Script
...
SkinUpateRate=25

Then in the Lua:

Function Initialize()
skinUpdateRate = SELF:GetOption('SkinUpdateRate')
end