• 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.

Variables

Status
Not open for further replies.
Yes.

But this is not always the case, sometimes there are variables that you only need to use for 0 seconds, meaning only for 2 or 3 lines of code and then you don't care about them throughout the rest of the code (TempLoc, TempUnit, TempGroup, TempWidget, TempInteger, etc...)

Those kinds of variables are fine to reuse.

Variables that store things like the caster of the spell to be used in a periodic trigger cannot be shared between spells. (Unless you have this group of spells in which only 1 may be used throughout the game. In that case, it's fine to make those spells share the same variables)
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
well if you have variables that are set in one trigger and used in another you shouldnt.
For instance if you set real a = 3 on init and you want to use it in trigger which has time - elapsed game time is 5.00 or unit starts the effect of an ability you shouldnt change that one.
Basickly if you want some variable to keep the stored value for later you shouldnt use that variable but if you have variable used only within one trigger you can.
Remember that if you use in one trigger wait you should not change those variables either.

Hope it helps :)

nevermind all this described Magtheridon96 above.

ps: Magtheridon96 do you ever sleep? :D you seem like you are here 24/7 :ogre_haosis:
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
if you do something like
  • Untitled Trigger 001
    • Set dmg = 150.00
    • Unit - Cause (Triggering unit) to damage (Triggering unit), dealing dmg damage of attack type Spells and damage type Normal
you can.
As I said, if it is used within one trigger and with no waits you can use it freely
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Variables are storage locations for data.

Global variables last the duration of the process (in WC3 this is the map session) and can be referenced by all functions in their scope (which is all custom functions in JASS).

Local variables last the duration of the stack frame the called function resides in. This means no two different calls will share the same local variables.

WarCraft III does not have efficient support for dynamic memory allocation so it is not possible to create new global storage locations for data during a session.
 
Status
Not open for further replies.
Top