• 🏆 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!

[Solved] Adding many events? /Changing timer intervall?

Status
Not open for further replies.
Level 3
Joined
Nov 12, 2018
Messages
43
1. Does adding too many events slow down the game over time? I'm currently running a trigger, which is adding one new event every ~25-50 seconds. And yes, it doens't work without adding new events, despite the event being always the same. :/

2. Is it possible to change the intervall time of an already created timer, without destroying and re-creating the timer?
 
Level 3
Joined
Nov 12, 2018
Messages
43
I found this:
Code:
native TimerStart           takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing

But I don't understand the last parameter. What does it mean?
 
It's the callback function which will run when the timer has expired.

JASS:
// this function runs when timer ended
function timer_expired takes nothing return nothing
    local timer clock = GetExpiredTimer() // this is the timer which expired
    // some other actions ..
endfunction

function timer_start takes nothing returns nothing

    // run the function "timer_expired" after 2.5 seconds, not periodically
    call TimerStart(CreateTimer(), 2.5, false, function timer_expired)

endfunction

In GUI, there is also a timer function to start it with a certain time. But in GUI you need to have a trigger to catch the callback/expired event, while in JASS you can write your own functions.
 
Level 3
Joined
Nov 12, 2018
Messages
43
I create a timer, each time a hero dies. (6 Players = 6 Heros.; 1/Player)
  • Hero Death 0
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • For each (Integer loop_HumanPlayerA) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Dying unit) Equal to player_HERO[loop_HumanPlayerA]
            • Then - Actions
              • Custom script: set udg_timer_HeroRevival[udg_loop_HumanPlayerA] = CreateTimer()
              • Countdown Timer - Start timer_HeroRevival[loop_HumanPlayerA] as a One-shot timer that will expire in (10.00 + ((Real((Hero level of player_HERO[loop_HumanPlayerA]))) x 1.50)) seconds
              • Countdown Timer - Create a timer window for timer_HeroRevival[loop_HumanPlayerA] with title Hero revival in:
              • Set timerW_HeroRevival[loop_HumanPlayerA] = (Last created timer window)
              • Countdown Timer - Hide timerW_HeroRevival[loop_HumanPlayerA]
              • Countdown Timer - Show timerW_HeroRevival[loop_HumanPlayerA] for (Player(loop_HumanPlayerA))
              • Trigger - Add to Hero Revival <gen> the event (Time - timer_HeroRevival[loop_HumanPlayerA] expires)
            • Else - Actions

I add the event to the following trigger:
  • Hero Revival
    • Events
    • Conditions
    • Actions
      • For each (Integer loop_HumanPlayerA) from 1 to 6, do (Actions)
        • Loop - Actions
          • Custom script: if GetExpiredTimer() == udg_timer_HeroRevival[udg_loop_HumanPlayerA] then
          • Cinematic - Ping minimap for (Player group((Player(loop_HumanPlayerA)))) at (Center of hss_Reg_SpawnHero[loop_HumanPlayerA]) for 2.00 seconds, using a Simple ping of color (100.00%, 100.00%, 100.00%)
          • Hero - Instantly revive player_HERO[loop_HumanPlayerA] at (Center of hss_Reg_SpawnHero[loop_HumanPlayerA]), Show revival graphics
          • Unit - Make player_HERO[loop_HumanPlayerA] face 270.00 over 0.00 seconds
          • Unit - Set mana of player_HERO[loop_HumanPlayerA] to 100.00%
          • Countdown Timer - Destroy timerW_HeroRevival[loop_HumanPlayerA]
          • Custom script: set udg_timer_HeroRevival[udg_loop_HumanPlayerA] = null
          • Custom script: endif

It's an array of timers. I set the array size to 6. But if I add the events in the "Hero Revival" trigger in the editor, the trigger doesn't fire for array sizes greater than 1.
That's why, I re-create the timer each time. If I don't re-create the timer over and over again, it's only working for array size 0-1. But I also have to add a new event for each re-created timer. Previously added events don't fire again. Despite "looking/being" the same. I guess they are different in jass?
 
Last edited:
For handle objects (basically all others than string, int, real, boolean, code, handle) array variables in GUI are only initialisized up to index 1. So timer[0] and timer[1] will exist by default. So you experience it doesn't work for index higher 1, because the timer itself doesn't exist and can't even start.

You can or ..
  • directly increase the number that GUI will use to initialisize timers (variable settings of your variable you can look for a value "1" and change it to "6")
  • create timer[2] - timer[6] once when game starts, and it will result in the same as the 1st solution
.. then the timer should be just never destroyed, and then also the events will always work, because the timer is never re-created, so remains always the same. (new timer requires new registration)
 
Level 3
Joined
Nov 12, 2018
Messages
43
increase the number that GUI will use to initialisize timers (variable settings of your variable you can look for a value "1" and change it to "6")
I already knew that, but I only did it for the timer window type variable. :hohum: Damn!
Now it works fine. Thank you for your help!

/solved
 
Status
Not open for further replies.
Top