• It's time to dig through Hive's model database and dust off some oldie but goldie models and enter Hive's Texturing Contest #31 : Repurposing! Click here to enter!
  • 🏆 Hive's 5th HD Modeling Contest: Creep Camp is now open! Click here to enter!

Local variables

Level 18
Jun 28, 2008
So if I am not mistaken the normal variables you declare are Global variables so is there a way to create local variables for GUI triggers? Just a quick variable to use for calculations.

And one more thing : If it is possible to create local variables, would that use less memory than Globals and wouldn't that be better to use?

Thanks for your time.
Level 14
Nov 18, 2007
You can abuse a bug in Jass where you overwrite a global with a local of the same name. But that only works once per trigger. Other than that, you'll have to stick with Jass to use locals. And no, local dont use less memory, their only advantage is their speed (i believe theyre about 9% faster than globals).
Level 7
Aug 15, 2007
when u declare a local with same name as global, you get into something called "shadowing" (where one var shadow the other). And WE doesnt detect tat so ye :p

and to use local in GUI:
on top of the gui in either of the Action/Condition or Event use custom script, example for an integer: local integer MyLocalVar

Dr Super Good

Spell Reviewer
Level 63
Jan 18, 2005
You can declare a reasnoable number of locals per function of atleast 30+ (any more is beyond practical use but probably possiable).
However the "shadowing" problem also occurs with passed parameters if you call those variables the same name as a global.

Also remember that you can not use locals in GUI in some structures if the locals were made at the start of the trigger (eg for groups and if statements) as those make new pointless functions and do not pass locals to them. You however can make new locals within them as they are new functions.

I would advise if you want to use locals to move straight to JASS as GUI's stupid structure will make your life difficult.
Level 12
Mar 16, 2006
Thanx people. So if I want to use a local variable I just use the call custom script :

  • Custom script - Local Variable Int = 0
where "int" is your variable name.

Thanks for the help. +rep

Use lowercase.

For GUI locals, you need to declare the locals at the beginning of the trigger. You can change them anywhere else in the trigger, however.

  • Custom script - local integer int
  • Custom script - set int = 200
Like so.
Level 7
Nov 4, 2006
Oh good, was wondering about GUI local variables also. BTW, how do you call these in GUI, like for damaging:

Cause Triggering unit to damage target unit, dealing (local real) damage of attack type Spells and damage type Normal.

I guess I should start learning JASS also.
Level 19
Aug 24, 2007
Since Triggering is local only shadowing target unit will be enough (since shadowing limit is 1)
lets say TARGET is a unit variable
Custom script: local unit udg_TARGET
Set TARGET = (Target of Ability Being Cast)
Wait WTFOWNED seconds
Cause (Triggering Unit) to do X damage to TARGET

Oh you want Damage Real as local too ?... well I guess you need to store it inside the custom value of TARGET in this way I guess....

The thing white line is called shadowing I guess, I mean declaring a local variable with name of a global variable
Its using benefit of a bug and can be only done once in a trigger, a second shadowing wont work