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

[General] Timer with Array problem

Status
Not open for further replies.
Level 2
Joined
Sep 1, 2011
Messages
12
  • Ultra Defense
    • Ereignisse
      • Unit - A unit starts the effect of an ability
    • Bedingungen
      • (Ability being cast) Gleich Ultra Defense ()
    • Aktionen
      • Set Temp_Unit[i] = (Triggering unit)
      • Set i = (Player number of (Triggering player))
      • Unit - Add Ultra Defense to Temp_Unit[i]
      • Countdown-Timer - Start UltraDefense[i] as a One-shot timer that will expire in 4.00 seconds
Thats ok so far (I hope at least) i'll fix the leaks later, just want this to work first. The problem comes now with the red part.

  • Ultra Defense Ends
    • Ereignisse
      • Zeit - UltraDefense[(Number of players)] expires
    • Bedingungen
    • Aktionen
      • Einheit - Remove Ultra Defense from Temp_Unit[i]
Zeit - UltraDefense[(Number of players)] expires
How do I refer to the right timer? I cant choose my variable "i". What kind of variable do I need?
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
I see what you want to do there. Im quite sure its not possible.

I think you will have to add an event for every timer that can expire.


e: btw, there is a mistake in the upper part, no?
'Set i = (Player number of (Triggering player))' should be done before Set Temp_Unit = (Triggering unit) if Im understanding this right.
And I hope you know that the way it is coded for every player only one unit can have the Ultra Defense ability, or bugs arise.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
afaik timer arrays have to be initialized and you have to set the array size (most variables use 0 or 1 as default, but timers and unit groups, i think, doesnt).
 
Level 5
Joined
Jan 12, 2010
Messages
132
  • Event
    • Map initialization
  • Conditions
  • Actions
    • Hashtable - Create a hashtable
    • Set - Table_CD = last created hashtable
  • Ultra Defense
    • Event
      • Unit - A unit starts the effect of an ability
    • Conditions
      • (Ability being cast) Gleich Ultra Defense ()
    • Actions
      • Set - Hash_unit = triggering unit
      • Custom script: set udg_Hash_key = GetHandleId(udg_Hash_unit)
      • If Then Else
        • Conditions
          • Triggering unit is in CoolDown_group = false
        • Actions
          • Hashtable - Save (x) as 1 of Hash_key in Table_CD
          • Unit - Add Ultra Defense to Hash_unit
          • Unit - Add triggering unit to CoolDown_group
          • Else
            • Hashtable - Save (x) as 1 of Hash_key in Table_CD
  • CoolDown
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
      • (Number of units in CoolDown_group) Greater than or equal to 1
    • Actions
      • Unit Group - Pick every unit in CoolDown_group and do (Actions)
        • Loop - Actions
          • Set - Hash_unit = picked unit
          • Custom script: set udg_Hash_key = GetHandleId(udg_Hash_unit)
          • Set Temp_real[1] = (Load 1 of (Hash_key) from Table_CD)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_real[1] Greater than or equal to 0.25
            • Then - Actions
              • Hashtable - Save (Temp_real[1] - 0.25) as 1 of (Hash_key) in Table_CD
            • Else - Actions
              • Hashtable - Clear all child hashtables of child (Key Hash_key) in Table_CD
              • Unit Group - Remove (Picked unit) fromCoolDown_group
              • Unit - REmove Ultra Defense to Hash_unit
  • Hashtable - Save (x) as 1 of Hash_key in Table_CD
where x = your expiring timer
it will 100% work, and is much more easier then using timers.If you use timers on many unit -> a lots of timer -> trouble tracking them.
 
Last edited:
Level 2
Joined
Sep 1, 2011
Messages
12
Thank you.

I'm not so good with Hashtables (actually i can't use them :vw_wtf:) so I would never do it with them but if I just copy your trigger its no problem.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
  • Ultra Defense
    • Ereignisse
      • Unit - A unit starts the effect of an ability
    • Bedingungen
      • (Ability being cast) Gleich Ultra Defense ()
    • Aktionen
      • Custom script : local unit u = GetTriggerUnit()
      • Custom script : local integer i = GetPlayerId(GetTriggerPlayer()) + 1
      • Set Temp_Unit[i] = (Triggering unit)
      • Set i = (Player number of (Triggering player))
      • Unit - Add Ultra Defense to Temp_Unit[i]
      • Wait 4 Seconds (or do a customed wait)
      • Custom script : set udg_i = i
      • Custom script : set udg_Temp_Unit[i] = u
      • Unit - Remove Ultra Defense from Temp_Unit[1]
      • Custom script : set u = null

Locals!

100x easier than above method
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
afaik timer arrays have to be initialized and you have to set the array size (most variables use 0 or 1 as default, but timers and unit groups, i think, doesnt).

Arrays initialize the indexes upto the initial size.

Default initial size is 1, so indexes 0 and 1 will be created automatically. Anything past that is a null value and need to be created either by setting the initial size or using CreateDialog/CreateTimer/CreateGroup etc.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I strongly advise learning JASS. By creating the script directly you have access to more advanced features of timers and triggers which lets what you do what you want more easily.

What you do is create an event in the timer expiration trigger for every player's timer. You then perform a linear search through the timer array to find which timer expired (the index). You can then use this index to remove the appropriate unit from the game.

Ugly, inefficient but good enough for the purpose at hand. You can always optimize it later.
 
Status
Not open for further replies.
Top