Re-using spell variables

Status
Not open for further replies.
Level 7
Joined
Dec 28, 2009
Messages
257
Hello there!

Just a small question on Variables:

In my map, i have, lets say, 50 spells that also have a trigger to go with them (when spell is cast, this trigger runs, to do some otherwise un-doable effect).
For items like "Caster", "Target", "Location of Target/Caster", "Units in area around target", "Level of ability", and so on, i use simple variablables - "Simple_Spell_Caster", "Simple_Spell_Target_Location", and so on.

My question is - if i use the same set of 5-10 integers for 50triggers, can they interact with each other in negative ways? Can one trigger not-finish midway, because another trigger will start using the same variables, and bug one or both? Can this be done without problems, if actions happen instantly, without any "Wait X seconds" ?

Thanks a lot for help!

If by any chance more clarification is needed, i can post some pictures of some triggers, to show what kind of things i talk about.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Use local variables (not supported by WC3 GUI) to avoid problems.

If an action triggers the event of another trigger, it will interrupt for that trigger. For example if Trigger A deals damage to unit U1 and Trigger B event is U1 is damaged then Trigger A will yield for Trigger B which will execute from the point of the damage action and after execution Trigger A will resume at the end of the damage action.
 
Level 11
Joined
Aug 6, 2009
Messages
697
If actions happen instantly, variables should be fine, this is the whole point of 'Temp' variables. However, if you set TempInt to 5 then wait 0.03 seconds, TempInt will be overwritten if it is being used anywhere else during the 0.03 second time frame. The only variables that I tend to worry about are integers used as a loop. In order to avoid variables being overwritten, people use MPI or MUI so that variables wont be overwritten when two spells are cast at the same time.
 
Usually it is not a problem, no. But on some things you still want to be careful with. When the trigger fires events which are registered to other triggers, then it might become dangerous.
For example:

Trigger1:

Event: Unit casts
Action:
Set Global_Integer = 1
Unit - Kill Triggering Unit
Game - Display (Global_Integer)

----

Trigger2:

Event: Unit dies
Action:
Set Global_Integer = 2

________________________________________

This will print 2 and not 1, because the event was fired in between with the "Kill Unit" line.
And apart from "Unit dies" other events might fire as well, so it is good to have seperated variables as rule of thumb for each system.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
In order to avoid variables being overwritten, people use MPI or MUI...
You still havent mentioned what they actually do.
MPI/MUI is not something you do, it is a classification of said script/trigger.

I don't know if others can (perhaps "enters region" if you move a unit?).
Unfortunately it doesn't... or at least with the SetUnitX() and SetUnitY() functions.

Issue order -> order event
Give exp -> hero gains a level event
Deal damage -> unit has taken damage event (maybe a unit dies as well)
Kill unit -> a unit dies event
ofc the custom event: "Game - Value Of Real Variable"

Using local variables is the best to avoid collision.
 
Status
Not open for further replies.
Top