• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Using globals instead of locals for instant actions

Status
Not open for further replies.
Level 10
Joined
May 24, 2016
Messages
365
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?
 
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.
 
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!
 
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.
Back
Top