How to detect which timer array nr. expires

Solu9

You can change this now in User CP.
Reaction score
216
How do I detect when a certain timer in a timer array expires?

As of right now all I can think of is to make an expiring trigger for every player in the game.

Example:
Gold Player 1
Events - Timer_A [1] expires
Conditions -
Actions -
Set gold of PlayerGroup_Gold [1] to 400

It would be so much easier if I could just set the event to something like "Events - Timer_A [any number] expires".
 
Hello, first of all, create a hashtable (let's say you named it Hashtable_Timers)
Imagine that you want to run Timer_A[1~12], as one-shot for a duration of (Random integer between 10 and 30), when one will expire, Player [1~12, corresponding to the expired timer array] will gain 100 gold.
Within the Hashtable_Timers, save the array of the timer as 1 with key(Last started timer) in Hashtable_Timers.
- pause there, I show you a complete exemple just in case, else, just go to the next "-" :

Event-
Every 10.00 seconds of game-time
Conditions-
Actions-
For Each Integer A from 1 to 12-
Start Timer_A[Integer A] as one-shot with a duration of (Random integer between 10 and 30)
Save (Integer A) in 0 of(Timer_A) in Hashtable_Timers
:end:

- that's how it should looks like.

Once this is done, you have a way to get back the Array of the timer with the expiring timer.
You just need to do something like:

Event-
Timer_A[1] expires
Timer_A[2] expires
...
Conditions-
Actions-
Add 100 gold to Player(Load 0 of(Expired Timer) in Hashtable_Timers)
:end:

I hope this was as clear as possible ^^' I'll keep an eye on this if you answer :)
 
It's funny. I have tried to track what array number expires soooo many times. In the end I always post my problems here. The weird thing is. More often than not, just a short time after I post I figure out a way to solve said problem.
This problem is no different.

My trigger looks a lot like yours:

Trigger:
  • Get Gold
    • Events
    • Time - Timer_A[1] expires
    • Time - Timer_A[2] expires
    • Time - Timer_A[3] expires
    • Time - Timer_A[4] expires
    • Time - Timer_A[5] expires
    • Time - Timer_A[6] expires
    • Time - Timer_A[7] expires
    • Time - Timer_A[8] expires
    • Time - Timer_A[9] expires
    • Time - Timer_A[10] expires
    • Time - Timer_A[11] expires
    • Time - Timer_A[12] expires
    • Conditions
    • Actions
    • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • (Remaining time for Timer_A[(Integer A)]) Greater than 0.00
    • Then - Actions
    • Else - Actions
    • Set PlayerGroup_Gold[(Integer A)] gold to 400


I'm no good with hashtables yet, however your example makes sense to me. Thanks a lot for the answer even though I found a different way to solve the problem :)
 
I doubt your trigger will work as it is. I think it will work fine only for the first timer that expires, eg:

Timer 1 expires, timers 2-12 are still counting -> everythings fine.
Timer 2 expires, timers 3-12 are still counting, but timer 1 expired already -> trigger runs for both player 1 and player 2.

Please correct me if I'm wrong. I think you could alternately set expired timer to some value and pause it but I don't know if it would work with several timers expired at same time.
 
@thorhunter.

I can see where you are going. The trigger used in this thread is a dummy trigger. I'll list the real triggers:

Trigger:
  • Set Lights Out
    • Events
    • Time - Elapsed game time is 5.50 seconds
    • Conditions
    • Actions
    • For each (Integer A) from 1 to (Number of players in (All players)), do (Actions)
    • Loop - Actions
    • Visibility - Create an initially Disabled visibility modifier for (Player((Integer A))) emitting Black mask across (Playable map area)
    • Set VisMod_LightsOut[(Integer A)] = (Last created visibility modifier)


Trigger:
  • Cast Lights Out
    • Events
    • Unit - A unit Starts the effect of an ability
    • Conditions
    • (Ability being cast) Equal to Dark Transit
    • Actions
    • Set PlayerGroup_LightsOut = (All enemies of (Owner of (Triggering unit)))
    • Player Group - Pick every player in PlayerGroup_LightsOut and do (Actions)
    • Loop - Actions
    • Visibility - Disable VisMod_Default[(Player number of (Picked player))]
    • Visibility - Enable VisMod_LightsOut[(Player number of (Picked player))]
    • Countdown Timer - Start Timer_LightsOut[(Player number of (Picked player))] as a One-shot timer that will expire in 10.00 seconds


Trigger:
  • End Lights Out
    • Events
    • Time - Timer_LightsOut[1] expires
    • Time - Timer_LightsOut[2] expires
    • Time - Timer_LightsOut[3] expires
    • Time - Timer_LightsOut[4] expires
    • Time - Timer_LightsOut[5] expires
    • Time - Timer_LightsOut[6] expires
    • Time - Timer_LightsOut[7] expires
    • Time - Timer_LightsOut[8] expires
    • Time - Timer_LightsOut[9] expires
    • Time - Timer_LightsOut[10] expires
    • Time - Timer_LightsOut[11] expires
    • Time - Timer_LightsOut[12] expires
    • Conditions
    • Actions
    • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • (Remaining time for Timer_LightsOut[(Integer A)]) Greater than 0.00
    • Then - Actions
    • Else - Actions
    • Visibility - Disable VisMod_LightsOut[(Integer A)]
    • Visibility - Enable VisMod_Default[(Integer A)]


So the question is if it becomes a problem since it's only a visibility modifier that get turned on (or back to normal as it should be anyway).

Edit:
Oh and isn't it only going to be a problem (in the add gold version of the trigger) if the timer is not a periodic timer?
 
Note that many functions return 0 if they experience errors. Your Trigger will work perfectly as long as every array index contains a valid trigger which is currently counting and has only been started one single time. If its nonexistent or has not been started, it might return 0. Also, if you do this:
Start Timer with x seconds
Pause Timer
Start Timer with y seconds
Remaining time will return x when the timer expired after y seconds.
End of the story, checking for remaining time will mostlikely work in your case, but in general, is a rather bad idea.
A better idea would be to directly compare expired timer to the timer in your array. Because GUI doesn't know timer comparisons, you will have to make an integer comparision with Key(Timer) == Key(Expired Timer) (though i never managed to get Key(variable) in GUI), get the keys using a custom script with "GetHandleId(udg_Timer[index])" or use a custom script with "set udg_someBoolVar = (GetExpiredTimer() == udg_Timer[index])" and use that boolean variable.
As for whats the difference between your two methods, these kind of problems are what hashtables were invented for. But for an array of only 12 elements, hashtables would serve no apparent benefit. If you have like 50 or 100 timers, then the hashtable would be what you have to go with.

Edit: oh, also, when you found your timer, you might as well skip the remaining actions to save some time where you circle through your array though you already found your timer
 
Hello back there! I could make it on my computer, was doing some random stuff that you doesn't care about at all.
Here is the way to do it, kinda simple in fact:
- Two variables : -1) Timer variable with array 12. (for the exemple, assume you named it "Your_Timers[]"
-2) Hashtable variable without array. (same reason a previously, name : "Yours_Timers_Hashtable"


First trigger, starting the timers:

Trigger:
  • Start the timers
    • Events
    • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
    • Hashtable - Create a hashtable
    • Set Your_Timers_Hashtable = (Last created hashtable)
    • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
    • Countdown Timer - Start Your_Timers[(Integer A)] as a One-shot timer that will expire in 5.00 seconds
    • Hashtable - Save (Integer A) as 1 of (Key (Last started timer)) in Your_Timers_Hashtable



Second trigger, 'finding' the expiring timer:

Trigger:
  • Which timer is ending
    • Events
    • Time - Your_Timers[1] expires
    • Time - Your_Timers[2] expires
    • Time - Your_Timers[3] expires
    • Time - Your_Timers[4] expires
    • Time - Your_Timers[5] expires
    • Time - Your_Timers[6] expires
    • Time - Your_Timers[7] expires
    • Time - Your_Timers[8] expires
    • Time - Your_Timers[9] expires
    • Time - Your_Timers[10] expires
    • Time - Your_Timers[11] expires
    • Time - Your_Timers[12] expires
    • Conditions
    • Actions
    • Player - Add 1000 to (Player((Load 1 of (Key (Expiring timer)) from Your_Timers_Hashtable))) Current gold
    • Game - Display to (All players) the text: ((Name of (Player((Load 1 of (Key (Expiring timer)) from Your_Timers_Hashtable)))) + has received 1000g!)




(I just tested it out, worked perfectly! :D)
 
Trigger:
  • MI
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to Timer <gen> the event (Time - Timer[(Integer A)] expires)

JASS:
 function Trig_Timer_Func001Func001C takes nothing returns boolean
    if ( GetExpiredTimer() == udg_Timer[bj_forLoopAIndex] ) then
        return false
    endif
    return true
endfunction

function Trig_Timer_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Timer_Func001Func001C() ) then
            call AdjustPlayerStateBJ( 1000, ConvertedPlayer(GetForLoopIndexA()), PLAYER_STATE_RESOURCE_GOLD )
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Timer takes nothing returns nothing
    set gg_trg_Timer = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Timer, function Trig_Timer_Actions )
endfunction
 
General chit-chat
Help Users
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top