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

Using globals instead of locals for instant actions

Status
Not open for further replies.
Level 9
Joined
May 24, 2016
Messages
298
Code:
globals
timer T
integer ID
endglobals

function Rain_Loop takes nothing returns nothing
set T = GetExpiredTimer()
set ID = GetHandleId(T)
... actions
call FlushChildHashtable(Hash,ID)
call PauseTimer(T)
call DestroyTimer(T)
endfunction
Sorry, didnt find some sort of my question. As you can see, for "instant actions" function I prefer to use global variables, coz it saves of a lot of time. So I wonder is it completely valid?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
If you use same global variable across multiple places, and "... actions" in your example causes another trigger to run which use same global variable you will encounter problems.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Explain what do you mean by that? Running a trigger exactly at the same time?
Lets say you have two triggers like this (I just made it up, so scenario may not make sense but problem is real):
  • Trigger1
    • Events
      • Unit - Enters region MIDDLE
    • Conditions
    • Actions
      • Set GlobalUnit = (Triggering Unit)
      • Unit - Cause GlobalUnit to damage MAP_BOSS
      • Unit - Pause GlobalUnit

  • Trigger2
    • Events
      • Unit - Take damage event
    • Conditions
    • Actions
      • ------- Create blood effect when a unit takes damage -------
      • Set GlobalUnit = (Damaged Unit)
      • Special Effect - create blood effect on GlobalUnit
      • Special Effect - (Destroy last created special effect)
In this example 2nd action of the Trigger1 causes Trigger2 to run, which overrides GlobalUnit variable. After Trigger2 is finished, execution is switched back to Trigger1 3rd action but GlobalUnit is a different unit now.


I will let IcemanBo explain better:
Strange location issues
[GUI] - [How-to] Loop In GUI!
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
A better question is: Why would you use variables in those triggers? @Ceday
It's completely unnecessary.
At the start of the post, I literally wrote I made up that scenario and it may not make sense. Something more realistic would be a GUI user who cleans all locations with same variable or someone who uses a global unit group for all temp stuff.
 
Status
Not open for further replies.
Top