Knuckle Cracker

Creeper World 4 => Making Maps, Units, and Scripts => Topic started by: 321k on March 05, 2021, 04:29:30 AM

Title: Detect Game Speed
Post by: 321k 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 ...
Title: Re: Detect Game Speed
Post by: GoodMorning 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
GetGameUpdateCount (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:getgameupdatecount)The time on the game-clock. 99% of time-related commands need to refer to this.
GetGameTickCount (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:getgametickcount)Like GetGameUpdateCount, but also counts paused frames. This is mostly useful for UI.
GetGameFrameCount (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:getgameframecount)A 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.
InvocationCount (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:invocationcount)Number of script-executions since the game was loaded. Probably a holdover from 4RPL development, but might find some use in UI.
GetLastExecutionCount (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:getlastexecutioncount)For 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.
GetUnitUpdateCount (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:getunitupdatecount)This 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.
SetUnitMiniMapTimeToEvent (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:setunitminimaptimetoevent)Affects when that countdown over the minimap will show up. You'll know if this is the command for you.
GetTimeString (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:gettimestring)Formatting function, turning a frame-count into text.
ElapsedTime (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:elapsedTime)The 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 (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:getgameframecount) or perhaps ElapsedTime (https://knucklecracker.com/wiki/doku.php?id=4rpl:commands: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.
Title: Re: Detect Game Speed
Post by: 321k 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.
Title: Re: Detect Game Speed
Post by: 321k 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.
Title: Re: Detect Game Speed
Post by: GoodMorning on June 25, 2021, 09:00:23 AM
That kind of animation is what ElapsedTime exists for.