I have 20 timers in an array and any given timer may or may not be running or expiring at any time. I want to be able to handle all the timers and their expiration actions in a single trigger. I thought maybe clever use of a For loop could do the job and just have every timer listed in the events, but I don't think there's a way to retrieve the ID in the array that belongs to the expiring timer. It seems that the only solution is to create 20 triggers, all of which with the exact same actions, except for a different number 0-19 used throughout each one, and to me that seems like such a waste.
you can have 20 events in one trigger. if it's an array it won't take you more than 5 minutes...though it is a bit monotonous. but then again, welcome to mapmaking! ANY good mapmaker has to be prepared to deal with monotony!
also, doing this is still efficient regarding how your map will actually run. having 20 events doesn't really cause additional network or processing lag, as complex maps often have hundreds and hundreds of events.
The problem isn't having the 20 timer expire events in one trigger, the problem is knowing which timer expired by its number in the array when I'm performing the actions. I could use <Expiring Timer>, but that wouldn't tell me its position in the array (0-19), which I need to perform several other tasks.
With an integer variable i. If the expiring timer is not in your array, the while loop will increment i up to 20, the if( i == 20 ) catches this and stops evaluation of the trigger. Otherwise, the variable i will be the index of the expired timer.
oh i see. so for example, in MyTimerArray[20], you want when MyTimerArray[x] expires to perform actions referring to "x"
i've run into issues like this before, and unfortunately the easiest way i've found to do this is make 21 triggers. 20 with the timer expiring, each setting a variable to the timer # that is expiring, then running a trigger with a local variable that inherits that value.
again, creating 20 triggers is inefficient on the developers side because you have to trudge through the monotony of creating 20 triggers that do the same thing, but players won't be effected by any addition of noticeable lag of any sort. also, if you simple have the 20 triggers run the "action" trigger, you don't have to cut+paste every change that's made.
the other way to do is have some periodic timer that runs through all the timers in a for loop, checks if they're expired, and runs a trigger if they are with an inherited value. this will save you time as a develop, but it will undoubtedly decrease the quality of your map because a:the trigger won't respond as efficiently and b:periodic events and unnecessary for loops generate lag. if you want your map to be clean and efficient, i would recommend against this.
frostmanx's example won't generate much noticeable lag, but you will still need to create 20 events, and technically it's not as clean during the maps actual run time as creating 21 triggers customized for each timer.
I have 20 timers in an array and any given timer may or may not be running or expiring at any time. I want to be able to handle all the timers and their expiration actions in a single trigger. I thought maybe clever use of a For loop could do the job and just have every timer listed in the events, but I don't think there's a way to retrieve the ID in the array that belongs to the expiring timer. It seems that the only solution is to create 20 triggers, all of which with the exact same actions, except for a different number 0-19 used throughout each one, and to me that seems like such a waste.
Thanks
you can have 20 events in one trigger. if it's an array it won't take you more than 5 minutes...though it is a bit monotonous. but then again, welcome to mapmaking! ANY good mapmaker has to be prepared to deal with monotony!
also, doing this is still efficient regarding how your map will actually run. having 20 events doesn't really cause additional network or processing lag, as complex maps often have hundreds and hundreds of events.
@CreamyT: Go
The problem isn't having the 20 timer expire events in one trigger, the problem is knowing which timer expired by its number in the array when I'm performing the actions. I could use <Expiring Timer>, but that wouldn't tell me its position in the array (0-19), which I need to perform several other tasks.
Use a this while loop as the first action in the trigger:
With an integer variable i. If the expiring timer is not in your array, the while loop will increment i up to 20, the if( i == 20 ) catches this and stops evaluation of the trigger. Otherwise, the variable i will be the index of the expired timer.
@frostmanx: Go
Aha, thank you. This should work perfectly.
oh i see. so for example, in MyTimerArray[20], you want when MyTimerArray[x] expires to perform actions referring to "x"
i've run into issues like this before, and unfortunately the easiest way i've found to do this is make 21 triggers. 20 with the timer expiring, each setting a variable to the timer # that is expiring, then running a trigger with a local variable that inherits that value.
again, creating 20 triggers is inefficient on the developers side because you have to trudge through the monotony of creating 20 triggers that do the same thing, but players won't be effected by any addition of noticeable lag of any sort. also, if you simple have the 20 triggers run the "action" trigger, you don't have to cut+paste every change that's made.
the other way to do is have some periodic timer that runs through all the timers in a for loop, checks if they're expired, and runs a trigger if they are with an inherited value. this will save you time as a develop, but it will undoubtedly decrease the quality of your map because a:the trigger won't respond as efficiently and b:periodic events and unnecessary for loops generate lag. if you want your map to be clean and efficient, i would recommend against this.