• 🏆 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 variable confusion

Status
Not open for further replies.
Level 7
Joined
Jul 4, 2007
Messages
249
Hi, this is starting to drive me crazy, I don't understand at all what is wrong. Can you help me? It doesn't read the If - target Equal to Pope_divineUnit, I have checked as you can see with text to see if it is the same unit and it is.

  • Time freeze unfreeze target
    • Events
      • Unit - Magic Arts Master 0005 <gen> Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (Houdini) Release Friend
    • Actions
      • Custom script: local unit udg_target
      • Set target = (Target unit of ability being cast)
      • Game - Display to (All players) the text: (target + (Name of target))
      • Game - Display to (All players) the text: (divine unit + (Name of Pope_divineUnit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • target Equal to Pope_divineUnit
        • Then - Actions
          • Unit - Remove Divine ProtectionBuff buff from target
          • Animation - Change target's animation speed to 100.00% of its original speed
          • Unit - Unpause target
          • Unit - Make target Vulnerable
          • Set Pope_divineUnitFreed = True
        • Else - Actions
          • Unit - Unpause target
          • Animation - Change target's animation speed to 100.00% of its original speed
      • Custom script: set udg_target = null
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
GUI (unintelligently, IMO) creates new functions for conditions that need to be evaluated. If you convert your trigger to JASS (Edit > Convert to Custom Text) you will see something like this:
JASS:
function Trig_Time_freeze_unfreeze_target_Func003C takes nothing returns boolean
    if ( not ( udg_target == udg_Pope_divineUnit ) ) then
        return false
    endif
    return true
endfunction
//...
function Trig_Time_freeze_unfreeze_target_Actions takes nothing returns nothing
    local unit udg_target
    if ( Trig_Time_freeze_unfreeze_target_Func003C() ) then
        //stuff here
    else
        //stuff here
    endif
endfunction
This, unfortunately, means that the local 'instance' of the target variable doesn't exist in the conditions so it instead checks the value of the global instance of target. You will have to assign a different global variable to the value of target before checking the condition and then use that instead. However, in this instance I don't see why you need target to be local at all, since you are not using any waits or timers. If your trigger has neither of those in it you can safely use all global variables without fear of them being overwritten.
 
Level 7
Joined
Jul 4, 2007
Messages
249
Thank you for your answer, do I not need to use local for position either? I've read that I need to remove it to prevent leaks.
  • Berserk
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • GDD_DamageSource Equal to Warrior Assassin 0004 <gen>
    • Actions
      • Custom script: local location udg_tempLoc
      • Set tempLoc = (Position of Warrior Assassin 0004 <gen>)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random real number between 0.00 and 10.00) Less than or equal to WarA_BerserkPercent
        • Then - Actions
          • Unit - Create 1 Dummy for (Owner of Warrior Assassin 0004 <gen>) at tempLoc facing tempLoc
          • Unit - Add a 0.20 second Generic expiration timer to (Last created unit)
          • Unit - Add (Dwight) BerserkDummy to (Last created unit)
          • Unit - Order (Last created unit) to Orc Shaman - Bloodlust Warrior Assassin 0004 <gen>
        • Else - Actions
      • Custom script: call RemoveLocation(udg_tempLoc)
Like in this example
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I suggest using either JASS or Lua directly. This way the life cycle of your local variables is not masked and additionally one does not have to rely on error prone behaviour such as name redeclaration. If one did not declare the local variable with the same name as a global variable then with JASS this error would be detected on map save.
 
Status
Not open for further replies.
Top