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

Question about Variables

Status
Not open for further replies.
Level 6
Joined
Dec 9, 2014
Messages
176
So, I was looking through the variables I have and I realized I have a ton and I'm still very early in the map building. I'm wondering if too many variables will eventually cause the map to become unstable or just not working at all? Also, is there anything else I should avoid using loads of?
 
Level 25
Joined
Sep 26, 2009
Messages
2,373
As many as possible. There's no exact number.

I get the feeling you don't even know what temporal variables are...
Most of the time, people create unique variables for each of their spells which they don't use anywhere else. For example a "HolyNovaCaster" variable would probably be used only for a "Holy Nova" spell, a "SliceAndDiceTarget" would be used exclusively for "Slice and Dice" spell, etc.
But actually most of these variables can be replaced with one "pack" of variables that are used for general purpose. Those are temporal variables.

Look at the code below. Let's say you have Holy Nova spell:
  • Holy Nova
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • Ability being cast equals to Holy Nova
  • Actions
    • Set HolyNovaCaster = (Triggering Unit)
    • Set HolyNovaPoint = (Positions of HolyNovaCaster)
    • Set HolyNovaGroup = Units within 400.00 range of HolyNovaPoint...
    • Unit Group - Pick every unit in HolyNovaGroup and do (Actions):
      • Unit - Set life of (Picked unit) to (Life of (Picked unit) + 50.00)
    • Set life of HolyNovaCaster to (Life of HolyNovaCaster + 100.00)
    • Custom script: call DestroyGroup(udg_HolyNovaGroup)
    • Custom script: call RemoveLocation(udg_HolyNovaPoint)
    • Set HolyNovaCaster = No unit
see all these HolyNova___ variables? Well, in this case you could replace them all for temporal variables. So what you would get is this:

  • Holy Nova
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • Ability being cast equals to Holy Nova
  • Actions
    • Set u1 = (Triggering Unit)
    • Set loc1 = (Positions of u1)
    • Set group = Units within 400.00 range of loc1...
    • Unit Group - Pick every unit in group and do (Actions):
      • Unit - Set life of (Picked unit) to (Life of (Picked unit) + 50.00)
    • Set life of u1 to (Life of u1 + 100.00)
    • Custom script: call DestroyGroup(udg_group)
    • Custom script: call RemoveLocation(udg_loc1)
    • Set u1 = No unit
See? The trigger is exactly the same, the difference is that I used different variables.
However I would be using these exact same variables for every other spells that I could.

There is one rule to using temporal variables:
Temporal variables never hold the information saved into them for any period of time. They simply have stuff saved into them in a trigger, then immediately they are used and also immediately destroyed. As you can see in the trigger above, there is no kind of wait between any of those actions.
The reason for that is simple: During any kind of delay (be it as small as 0.01 second) it is still possible for other trigger to fire and re-write the information that has been saved into the temporal variable.

Let's say our Holy Nova spell shall pick all allies nearby the caster when the Holy Nova spell has been cast and then periodically heal those picked units.
  • Holy Nova Cast
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • Ability being cast equals to Holy Nova
  • Actions
    • Set u1 = (Triggering Unit)
    • Set loc1 = (Positions of u1)
    • Set HolyNovaGroup = Units within 400.00 range of loc1...
    • Set life of u1 to (Life of u1 + 100.00)
    • Custom script: call RemoveLocation(udg_loc1)
    • Set u1 = No unit
  • Holy Nova HoT
  • Events
    • Time - Every 1.00 second of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in HolyNovaGroup and do (Actions):
      • Unit - Set life of (Picked unit) to (Life of (Picked unit) + 50.00)
As you can see, I use a unique HolyNovaGroup, because it saves the information for some period of time, hence I couldn't use temporal variable. However you can also see that anywhere else I used temporal variables!
That's why I wrote there is no exact number.
---
So with temporal variables, you will pretty much get rid of useless variables.
 
Level 6
Joined
Dec 9, 2014
Messages
176
Whoa. 600k, well that's good I suppose then lol. I didn't know what a temporary variable is. Well, anyhow, thanks for the responses. Anything else I should work about not over doing? I know imports easily hit the data cap. Should I be worried about doodads, abilities, units, triggers, or anything like that?
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
When using GUI variables you can hit the initialization thread operation limit causing not all triggers to be created. This is especially easy if you set the size of arrays to very large values.

Arrays in WC3 are dynamic arrays so do not have a size declaration. Instead GUI uses that size to initialize the array in a loop to the default value defined. Doing this consumes operations so with enough you can hit the operation limit of the initialization thread which will stop everything being initialized.
 
Level 6
Joined
Dec 9, 2014
Messages
176
The biggest Array I'm going to be having will be around 20, is that too many? Also, what's the limit where triggers begin getting stopped?
 
Level 25
Joined
Sep 26, 2009
Messages
2,373
While it is true that size is important for unit groups, timers, etc., all can be created via custom script still... that's imo better choice as you have more control over the amount (since it's dynamic) than the static amount set via variable size.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
My map has probably 550k Variables.

If you have anywhere close to that you are coding incorrectly.

The biggest Array I'm going to be having will be around 20, is that too many? Also, what's the limit where triggers begin getting stopped?

Take a look at my tutorial Things you should know when using triggers / gui. The section on the variable editor will explain more on what variable to initialize and why.
 
Level 6
Joined
Dec 9, 2014
Messages
176
I don't know anything about custom scripts, I barely know a little about GUI lol. I just finished a bunch more work on my map. Gonna upload what I have to my development thread if anyone want's to check it out.
 
Status
Not open for further replies.
Top