Detect Game Speed

321k · 461

321k

  • Jr. Member
  • **
    • Posts: 20
on: March 05, 2021, 04:29:30 am
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

  • Community Guild
  • *****
    • Posts: 3452
  • (Pusillanimous)
Reply #1 on: March 05, 2021, 06:54:54 pm
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

  • Jr. Member
  • **
    • Posts: 20
Reply #2 on: March 08, 2021, 09:55:35 am
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.
« Last Edit: March 08, 2021, 10:41:47 am by 321k »



321k

  • Jr. Member
  • **
    • Posts: 20
Reply #3 on: June 20, 2021, 06:54:37 am
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

  • Community Guild
  • *****
    • Posts: 3452
  • (Pusillanimous)
Reply #4 on: June 25, 2021, 09:00:23 am
That kind of animation is what ElapsedTime exists for.

A narrative is a lightly-marked path to another reality.