Detect Game Speed

Started by 321k, March 05, 2021, 04:29:30 AM

Previous topic - Next topic

321k

Is there any script command to detect which speed the game is running or the real world time or something like processor ticks? As I understand this, the commands like GetGameUpdateCount, GetUnitUpdateCount, GetGameTickCount are not related to real world time.

Example: I want to show up an ObjText same real world duration regardless game speed. Or adapt the animation speed of an unit moving slowly up and down ...

GoodMorning

Ah, game time-related functions ... there are a fair few of these, and I'll list them for anyone else who finds this thread. OP, you could skip to the TL;DR at the end if you chose.












CommandDescription
GetGameUpdateCountThe time on the game-clock. 99% of time-related commands need to refer to this.
GetGameTickCountLike GetGameUpdateCount, but also counts paused frames. This is mostly useful for UI.
GetGameFrameCountA very lag-sensitive command, good for smooth animations. The number of user-screen-updates the game has done. This can be up to 2 for every time GetGameUpdateCount increases, but don't count on it. The game can and will skip the non-"update" frames.
InvocationCountNumber of script-executions since the game was loaded. Probably a holdover from 4RPL development, but might find some use in UI.
GetLastExecutionCountFor very advanced scripts detecting problems. Or maybe for noticing when something is likely to cause lag. Again, probably a relic from when 4RPL was being built.
GetUnitUpdateCountThis increases like GetGameUpdateCount, but with "zero" as the time the unit was created. You could get the same effect with a subtraction. This will be marginally faster, though.
SetUnitMiniMapTimeToEventAffects when that countdown over the minimap will show up. You'll know if this is the command for you.
GetTimeStringFormatting function, turning a frame-count into text.
ElapsedTimeThe real-world time since you started CW4. This is the only function which refers to a clock that isn't affected by lag. Never let game logic be affected by this, but it has uses for UI and perhaps animation.

TL;DR:
For the original question only: The command you're looking for for animation is GetGameFrameCount or perhaps ElapsedTime for showing a sign on-screen. I'd avoid ElapsedTime where possible, though - if someone pauses and leaves as your text comes up, they might miss it entirely.
A narrative is a lightly-marked path to another reality.

321k

#2
ElapsedTime. It's more for adapting animation to game speed, so no problem if somebody misses something. Maybe I test GetGameFrameCount, too.

Thanks so much. The 1.3 Update brings all the funtions I was missing.

321k

Feature Reques: GetUserGameSpeed returns 0, 1, 2 for the 3 possible game speeds. The number should be well know by the game, it would just read it from mem and return it in function.

Would allow to build some nice animations, which disable in higher game speed.

GoodMorning

That kind of animation is what ElapsedTime exists for.
A narrative is a lightly-marked path to another reality.