• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I thought I will need to make them for every spell, that would suck
Just like Mag said, if the spell has Instant Effect, you can use TempReal (damage or something), but if it is stored for future use (Periodic Spell for example), you should not use the same variable as it will collide and will bug your data handling.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
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