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

Variable Problem

Status
Not open for further replies.
Level 3
Joined
Apr 9, 2010
Messages
32
Ok, here's the problem. I just started doing in sc2 editor and have some problems..

Anyway, here is the trigger. I want simple countdown system but number 9 keeps showing all the time. I know it's because of the event trigger which sets Number_Variable to its initial value every time, but how to override that?


Number
Events
Timer - Every 1.0 seconds of Game Time
Local Variables
Number_Variable = 10 <Integer>
Conditions
Actions
Variable - Modify Number_Variable: - 1
Text Tag - Create a text tag with the text (Text(Number_Variable)) for (All players), using a font size of 24, at (Center of Region 001) and height offset 1.0, initially Visible, and fog of war enforcement set to false
Text Tag - Show (Last created text tag) for (All players)
Text Tag - Set the velocity of (Last created text tag) to 1.0 coordinates per second at an angle of 90.0 degrees from horizontal
Text Tag - Set Duration time for (Last created text tag) to 2.0 seconds
 
Level 3
Joined
Apr 9, 2010
Messages
32
sry for missposting...

i still cant find out how to make damn global variable. -.-
 
Level 9
Joined
Nov 4, 2007
Messages
931
Could still use a local variable, only instead of using Every 1.0 seconds event you could use simply Map Initialization, Time Elapsed, or no event and fire it from a different trigger telling it to run. Basically you would just have to use Repeat #(10) times and add a Wait time of 1.0 seconds at the end of the loop (waits in SC2 are far more accurate than those in WC3). Either way works fine though.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I forgot to add that locals only take up stack space when the function is run rather than globals which take up memory space.

Thus, locals do not count towards the virtual machine code size limit (next to the instructions that create / manipulate them which get stored in memory) and instead count towards the stack size limit (which is near impossible to reach under normal circamstances unless huge variables or extensive recursive calls occur).

Globals are prety much the opposite, being allocated in the virtual machine memory and not consuming any stack space at all.

Do not think any variable is better... They both are equally useful and which gets used depends on the situation. Locals for example can not be retained outside of a function call due to being poped from the stack and lost, so for representing a group of players in team 1 for use throughout your triggers they would be completly usless where as a global perfect for this task.
 
Status
Not open for further replies.
Top