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

[Trigger] Locals and conditions failing?

Status
Not open for further replies.

Br0

Br0

Level 4
Joined
May 4, 2012
Messages
102
Why doesn't this work?

[trigger=]
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Load
Actions
Custom script: local unit udg_caster = GetTriggerUnit()
Custom script: local unit udg_tgtdunit = GetSpellTargetUnit()
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of tgtdunit) Equal to Peon
Then - Actions
Unit - Add Battle Stations - peon to caster
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of tgtdunit) Equal to Grunt
Then - Actions
Unit - Add Battle Stations - grunt to caster
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of tgtdunit) Equal to Raider
Then - Actions
Unit - Add Battle Stations - raider to caster
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of tgtdunit) Equal to Tauren Chieftain
Then - Actions
Unit - Add Battle Stations - hero tauren chief to caster
Else - Actions
Custom script: set udg_tgtdunit = null
Custom script: set udg_caster = null
[/trigger]
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
How are you able to use the GUI actions to add abilities to local units? Have you declared the global variables caster and tgtdunit in the variable editor?
Locals > globals. If you have 2 variables with the same name, 1 a global and the other a local, then the trigger will only read the local.
This is useful to trick GUI into being able to use locals the way Br0 did (by creating a local with the same name as the global).
He needs to have it initialized in the variable editor, otherwise he cannot use it in GUI, so I think he did do that :)


In any case, why are you even doing this trick? There aren't any waits in your trigger or anything else that could cause a variable mix-up.
Besides, triggering unit is always a local so there's no need for that.
Just use the normal GUI set variable actions, see if that works.
 
Last edited:

Br0

Br0

Level 4
Joined
May 4, 2012
Messages
102
The triggering unit wouldn't fail however the target unit of ability being cast would surely fail on being MUI wouldn't it?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
The triggering unit wouldn't fail however the target unit of ability being cast would surely fail on being MUI wouldn't it?
Here's an example:
  • Actions
    • Custom script: local unit udg_target = GetSpellTargetUnit()
    • Unit - Add Invisibility to target
    • Custom script: set udg_target = null
  • Actions
    • Set target = (Target unit of ability being cast)
    • Unit - Add Invisibility to target
Do you think both of them are equally MUI?
(Answer: they are both MUI).

This is actually what your trigger does: it just sets a unit variable and adds an ability to that unit.
Since there are no waits, everything happens in an instant: variables cannot be overwritten while a trigger is still running.

If you had done this:
  • Actions
    • Set target = (Target unit of ability being cast)
    • Wait 1.00 seconds
    • Unit - Add Invisibility to target
This is NOT MUI. If people cast it fast enough it will fail.
Using locals here is a good option.


I hope you got the point of my stupid trigger-examples? If not, I can try to explain it with words as well :)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Of course I know locals are better than globals...
I was just confused because I didn't know of this trick because I never use GUI.
Oh no, I don't mean "better than", I mean they have a higher priority. So locals > globals priority-wise :)
So a local named "unit" will always be used in a trigger, even when there's a global named "unit".
I'm sorry for the confusion, didn't mean to insult you by spouting out obvious things.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Conditions in GUI are organized in private functions. Locals only exist within a function call. So in the above trigger, the conditions read the global variable.

In addition to waits presenting a problem with global variables for MUIness, you should also pay attention if you have actions there that trigger other parts of the code.
 
Level 5
Joined
Sep 22, 2012
Messages
90
noob here, how am i suppose to know if a variable is global/local. I know from c/c++ a global is something that can be used anywhere and it can be supplied to other function that can be changed by using refs and ptrs. A local in the other hand can be only within a function and it has a limited scope. i'm just not sure how to classify thing here in trigger editor :(
 
Status
Not open for further replies.
Top