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

[General] Custom Script Errors

Status
Not open for further replies.
Level 6
Joined
Sep 11, 2006
Messages
172
So I'm putting together a trigger using local player variables and Jass helper is telling me I have errors.

I have a function just like this one in another trigger. In fact, I copied that function for use in this new trigger. The only difference in the custom script is that I changed the global variable being used to reference the owner of a particular unit.

Jass helper keeps telling me that my local player variable is undeclared and that the "if GetLocalPlayer()==p then" part of the script is an invalid comparison.


  • Storm
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: local player p
      • Set sound = No sound
      • Set sound = LightningBolt1 <gen>
      • Sound - Play sound
      • Set TempGroup = (Units in (Playable map area)((Unit-type of (Matching unit)) Equal to Window Shine))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Unit - Unhide (Picked unit)
          • -------- Local Player --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Hunting Rect Copy 2 <gen> contains Hero[1]) Equal to True
            • Then - Actions
              • Set sound = No sound
              • Set sound = RollingThunder1 <gen>
              • Custom script: if GetLocalPlayer() == GetOwningPlayer(udg_Hero[1]) then
              • Sound - Play sound
              • Custom script: endif
              • Custom script: set p = GetOwningPlayer(udg_Hero[1])
              • Custom script: call SetCineFilterTexture("ReplaceableTextures\\CameraMasks\\White_mask.blp")
              • Custom script: call SetCineFilterStartColor(0,0,0,0)
              • Custom script: call SetCineFilterEndColor(0,0,0,255)
              • Custom script: call SetCineFilterDuration(1)
              • Custom script: if GetLocalPlayer()==p then
              • Custom script: call DisplayCineFilter(true)
              • Custom script: endif
            • Else - Actions
          • -------- Local Player --------
          • Wait 1.00 seconds
          • Unit - Hide (Picked unit)
          • Wait 0.25 seconds
          • Unit - Unhide (Picked unit)
          • Wait 0.25 seconds
          • Unit - Hide (Picked unit)
          • Wait 0.25 seconds
          • Unit - Unhide (Picked unit)
          • Wait 1.00 seconds
          • Unit - Hide (Picked unit)
 
Basicly, if you declare a local variable you only have access
to it in the function where declared. (that's why it's called local)

Now the problem lies in the "PickEveryUnitAndDoActions" function.
It calles a new function for EveryUnitInGroup, which is not really mentionable in GUI.
So your previous declared local variables falls out of scope,
and you don't have access anymore to it in this group function.

For solution you need to declare the local in the loop function of the unit group.
So declare "local player p" under this line, and it should not throw a syntax error:
  • Loop - Actions

Btw, "(Picked unit)" works like a global variable, so it may be overwritten.
If it gets (and it probably will) overwritten during your "Wait" operations, you will have wrong results,
as it won't refer anymore to the actualy "Picked unit" that you picked at first.

And I'm not even sure you can work with "Wait" actions like that in the group loop function.
Wait aka TriggserSleepAction usually doesn't work in normal functions, but only (almost I think^^)
in the normal Action part of the trigger. (As we know the group loop is actually a seperated function)

But you can just do it like this:

PickAllUnitsAndDo - Hide
Wait X seconds
PickAllUnitsAndDo - Unhide
Wait X seconds
PickAllUnitsAndDo - Hide
Wait X seconds
...
 
Status
Not open for further replies.
Top