• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Timer Utils

Status
Not open for further replies.
Level 3
Joined
Nov 3, 2017
Messages
34
I'm here studying the code TimerUtils, just for the sake of interest, I have little knowledge, and it became interesting that's it
JASS:
static if USE_HASH then
                set tT[0] = CreateTimer()
            else
                debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: No Timers In The Stack! You must increase 'QUANTITY'")
                return null
            endif

I just wanted to know from experienced people what this part of the code is doing. In particular, what does the operator do "if" - return?
 
Level 7
Joined
Dec 28, 2014
Messages
83
From what I understand, if USE_HASH is true, JassHelper will write the first statement in compile time, if USE_HASH is false, JassHelper will write the second statement instead in compile time. This happens because it uses "static if".

For the return null, the function will stop there and the remaining lines below will be ignored. The return value of the function becomes null since it encountered an error.
 
^exactly as he said.

In the context of the system, TimerUtilsEx creates a pool of timers on map initialization (if USE_HASH is false) since constantly using CreateTimer() and DestroyTimer() is a little more expensive.

When you use NewTimer() with USE_HASH = false, it'll try to get one from that pool of timers. If all of them are currently being used (i think by default it creates 256 timers on initialization), it'll show you that error.

If USE_HASH = true, the system does not create any timers on map initialization. It still has a "pool" of timers that it reuses, but if there are none available in that pool, it will create a new one for you to use.
 
Status
Not open for further replies.
Top