I'm trying to find or make a deltaTime variable in zscript for HUD mod

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
DonDevRed
Posts: 49
Joined: Sat Nov 14, 2020 6:32 pm
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

I'm trying to find or make a deltaTime variable in zscript for HUD mod

Post by DonDevRed »

Howdy, I'm trying to find or make a deltaTime variable, or a version of TicFrac that stays consistent even in different framerate settings, for a HUD mod I made that I'm trying to improve. The issue is that due to using TicFrac in animating it, the speed of animation varies depending on the framerate settings (max framerate, vertical synch and interpolation) and in cases, the animation plays way to fast.

Since I couldn't really find a deltaTime-like variable in anything available for zscript, I'm trying to make one by dividing TicFrac to the framerate of the running game. Something like:

double deltaTics = TicFrac / *insert framerate variable here*;

But I can't find a framerate variable either in zscript...

Is there such a variable? Or is there a better way to get a consistent tic rate without the framerate problem?
User avatar
Player701
 
 
Posts: 1706
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: I'm trying to find or make a deltaTime variable in zscript for HUD mod

Post by Player701 »

I've just checked my own code that I use for some primitive HUD animations, and it relies on the MSTimeF function, which returns the amount of time passed since the start of the game in milliseconds. This is also better than tics because your animation parameters do not depend on the tic rate, and no conversion is required to express them in human-readable units (e.g. distance per second).

When you begin your animation, you should call this function once and remember the return value. Then, for each animation frame, call it again and subtract the stored return value from the current one - this gives you the delta in milliseconds between the current and previous frame. Store the new return value, rinse, repeat.

Return to “Scripting”