Little help with local variable

MP®

Member
Reaction score
11
Ok I made a trigger with a few 'If-then-else' actions.

Now if certain conditions are right, a unit is being replaced. Now I want this replaced unit to be paused, wait 1 second and then unpause again.

So I make a custom script (after replacing the unit) to make the replaced unit a local variable. But this doesn't seem to work.. Looks like you can only local units at the start of a trigger or something? Or how does that work? How can I do this?

this is the trigger, its not finished yet there are also some other things that I have to fix, but now just look only to the thing with the 'local unit r':

Trigger:
  • Click door
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • ((Target unit of issued order) is paused) Not equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(smart))
          • (Issued order) Equal to (Order(thunderbolt))
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Target unit of issued order)) Equal to Doors (Open)
          • (Unit-type of (Target unit of issued order)) Equal to Doors (Closed)
    • Actions
      • Custom script: local unit u = GetOrderTargetUnit()
      • Set Temp_Point = (Position of (Triggering unit))
      • Set Temp_Point2 = (Position of (Target unit of issued order))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between Temp_Point and Temp_Point2) Less than or equal to 250.00
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Player number of (Owner of (Triggering unit))) Less than 6
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Target unit of issued order) has buff Unlocked ) Equal to True
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of (Target unit of issued order)) Equal to Doors (Closed)
                    • Then - Actions
                      • Unit - Replace (Target unit of issued order) with a Doors (Open) using The old unit's relative life and mana
                      • Unit - Pause (Last replaced unit)
                      • Custom script: local unit r = GetLastReplacedUnitBJ()
                      • Custom script: set udg_Doors = r
                      • Animation - Play (Last replaced unit)'s death alternate animation
                      • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point2 facing Default building facing degrees
                      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                      • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
                      • Wait 1.00 game-time seconds
                      • Unit - Unpause Doors
                      • Custom script: set r = null
                    • Else - Actions
                      • Unit - Pause (Target unit of issued order)
                      • Custom script: set udg_Doors = u
                      • Set Temp_Point3 = (Position of (Target unit of issued order))
                      • Animation - Play (Target unit of issued order)'s birth animation
                      • Wait 1.00 game-time seconds
                      • Unit - Replace Doors with a Doors (Closed) using The old unit's relative life and mana
                      • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point3 facing Default building facing degrees
                      • Custom script: call RemoveLocation (udg_Temp_Point3)
                      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                      • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of (Target unit of issued order)) Equal to Doors (Closed)
                    • Then - Actions
                      • Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cffff0000Doors loc...
                    • Else - Actions
                      • Unit - Pause (Target unit of issued order)
                      • Custom script: set udg_Doors = u
                      • Set Temp_Point3 = (Position of (Target unit of issued order))
                      • Animation - Play (Target unit of issued order)'s birth animation
                      • Wait 1.00 game-time seconds
                      • Unit - Replace Doors with a Doors (Closed) using The old unit's relative life and mana
                      • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point3 facing Default building facing degrees
                      • Custom script: call RemoveLocation (udg_Temp_Point3)
                      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                      • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Target unit of issued order)) Equal to Doors (Closed)
                • Then - Actions
                  • Unit - Replace (Target unit of issued order) with a Doors (Open) using The old unit's relative life and mana
                  • Unit - Pause (Last replaced unit)
                  • Custom script: local unit r = GetLastReplacedUnitBJ()
                  • Custom script: set udg_Doors = r
                  • Animation - Play (Last replaced unit)'s death alternate animation
                  • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point2 facing Default building facing degrees
                  • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                  • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
                  • Wait 1.00 game-time seconds
                  • Unit - Unpause Doors
                  • Custom script: set r = null
                • Else - Actions
                  • Unit - Pause (Target unit of issued order)
                  • Custom script: set udg_Doors = u
                  • Animation - Play (Target unit of issued order)'s birth animation
                  • Wait 1.00 game-time seconds
                  • Unit - Replace Doors with a Doors (Closed) using The old unit's relative life and mana
        • Else - Actions
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Temp_Point2)
      • Custom script: set u = null
 

jnZ

I
Reaction score
64
just creat the local variable at the beginning and set it later

Beginning:
local unit r = null

When you need it:
set r = GetLastReplacedUnitBJ() and NOT local unit r = GetLastReplacedUnitBJ()
 

MP®

Member
Reaction score
11
oh and to be sure:

So when I need it, I have to do the custom script:

set r = GetLastReplacedUnitBJ()

and

set udg_ReplacedUnit = r

right? To make my GUI choose the local variable?


I'm sorry this whole local variable stuff is kinda new to me..
 

MP®

Member
Reaction score
11
Ok something in my trigger still doesn't work right, but it doesn't have to be something with the local variables.. But can you use 1 normal variable for 2 locals in 1 trigger?

Like this:

local unit u = GetOrderTargetUnit()
local unit r = null
set udg_Unit = u

then use it,
and later in the trigger:

set udg_Unit = r
and use that one.

That should not be a problem, am I right?
 

jnZ

I
Reaction score
64
you are right. thats not a problem. just like its not a problem to fill a cup with water, drink it and afterwards fill it with cola and drink it again
 

MP®

Member
Reaction score
11
haha oke thnx

But then I can't find what's the problem in this trigger..

maybe some of you?

Trigger:
  • Click door
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(smart))
          • (Issued order) Equal to (Order(thunderbolt))
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Target unit of issued order)) Equal to Doors (Open)
          • (Unit-type of (Target unit of issued order)) Equal to Doors (Closed)
    • Actions
      • Custom script: local unit u = GetOrderTargetUnit()
      • Custom script: local unit r = null
      • Custom script: set udg_Doors = u
      • Wait 0.10 game-time seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Doors is paused) Equal to True
        • Then - Actions
        • Else - Actions
          • Set Temp_Point = (Position of (Triggering unit))
          • Set Temp_Point2 = (Position of Doors)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_Point and Temp_Point2) Less than or equal to 250.00
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Player number of (Owner of (Triggering unit))) Less than 6
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Doors has buff Unlocked ) Equal to True
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of Doors) Equal to Doors (Closed)
                        • Then - Actions
                          • Unit - Replace Doors with a Doors (Open) using The old unit's relative life and mana
                          • Unit - Pause (Last replaced unit)
                          • Custom script: set r = GetLastReplacedUnitBJ()
                          • Custom script: set udg_Doors = r
                          • Animation - Play (Last replaced unit)'s death alternate animation
                          • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point2 facing Default building facing degrees
                          • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                          • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
                          • Wait 1.00 game-time seconds
                          • Unit - Unpause Doors
                          • Custom script: set r = null
                        • Else - Actions
                          • Unit - Pause Doors
                          • Animation - Play Doors's birth animation
                          • Wait 1.00 game-time seconds
                          • Unit - Replace Doors with a Doors (Closed) using The old unit's relative life and mana
                          • Custom script: set u = null
                          • Set Temp_Point3 = (Position of (Last replaced unit))
                          • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point3 facing Default building facing degrees
                          • Custom script: call RemoveLocation (udg_Temp_Point3)
                          • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                          • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of Doors) Equal to Doors (Closed)
                        • Then - Actions
                          • Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cffff0000Doors loc...
                        • Else - Actions
                          • Unit - Pause Doors
                          • Animation - Play Doors's birth animation
                          • Wait 1.00 game-time seconds
                          • Unit - Replace Doors with a Doors (Closed) using The old unit's relative life and mana
                          • Custom script: set u = null
                          • Set Temp_Point3 = (Position of (Last replaced unit))
                          • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point3 facing Default building facing degrees
                          • Custom script: call RemoveLocation (udg_Temp_Point3)
                          • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                          • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of Doors) Equal to Doors (Closed)
                    • Then - Actions
                      • Unit - Replace Doors with a Doors (Open) using The old unit's relative life and mana
                      • Unit - Pause (Last replaced unit)
                      • Custom script: set r = GetLastReplacedUnitBJ()
                      • Custom script: set udg_Doors = r
                      • Animation - Play (Last replaced unit)'s death alternate animation
                      • Unit - Create 1 Activate Dummy for Neutral Extra at Temp_Point2 facing Default building facing degrees
                      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                      • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Last replaced unit)
                      • Wait 1.00 game-time seconds
                      • Unit - Unpause Doors
                      • Custom script: set r = null
                    • Else - Actions
                      • Unit - Pause Doors
                      • Animation - Play Doors's birth animation
                      • Wait 1.00 game-time seconds
                      • Unit - Replace Doors with a Doors (Closed) using The old unit's relative life and mana
                      • Custom script: set u = null
            • Else - Actions
          • Custom script: call RemoveLocation (udg_Temp_Point)
          • Custom script: call RemoveLocation (udg_Temp_Point2)
      • Custom script: set u = null


The problem is: you can click on the door to open it when standing near. (well, you have to be player #6 or higher, or the door should have the 'unlocked' buff)

Anyway, to prevent weird things to happen when clicking very rapidly after eachother (like strange animations, and multiple doors placed on eachother) I wanted the door to be paused for 1 second (while playing the open/close animation) and while the door is paused, clicking on it should not do anything.

But I can't get it working, I now even build a buffer of 0.10 sec, to be sure that the door is paused, and it gets harder to get the multiple doors after clicking very rapidly, but it's still possible... How come?
 

MP®

Member
Reaction score
11
Because there are multiple doors in the map which all have to be able to open/close at the same time..

Maybe I can use a dummy to cast a buff or something and let the trigger check for that buff.. But that is the same principle, so I wonder if that will work..

Or else I could pause the unit that is clicking (order-smart) on the door for maybe 0.10 sec..

But its still strange that this trigger just doesn't work.. Does anyone know what's the problem?
 

jnZ

I
Reaction score
64
i didn't take the time to look at your trigger yet, but if you take the time to describe whats actually happening and whats exactly not working, it wouldn't be much of a problem
 

MP®

Member
Reaction score
11
The idea is: you can click on the door to open it when standing near (the 'closed door unit' will be replaced by an 'open door unit' and play open/close animation). (well, you have to be player #6 or higher, or the door should have the 'unlocked' buff)

Anyway, to prevent weird things to happen when clicking very rapidly after eachother (like weird animations, and multiple doors placed on eachother) I wanted the door to be paused for 1 second when you click it (while playing the open/close animation) and while the door is paused, clicking on it should not do anything.

But I can't get it working, weird things still occur when clicking very rapidly.. I now even build a buffer of 0.10 sec, to be sure that the door is paused, and it gets harder to get the multiple doors after clicking very rapidly, but it's still possible... How come?
 

jnZ

I
Reaction score
64
i understood what you were trying to accomplish. i wanted you to explain what those "weitd things" are.
 

MP®

Member
Reaction score
11
Well, it would look weird if the open animation isn't finished and suddenly starts the closed animation. Thereby, I don't know why, but if you click really fast, multiple doors get spawned on the same place. It's like the replace action didn't finish removing the original door but already placed a new one, or something. Eventually, you have multiple door-units at exactly the same point, but for example 1 is open and 1 is closed, and you can't open the one that is closed, because when you want to click it, you click another one that is open, etc.
 

jnZ

I
Reaction score
64
heres a question: why do you use a local variable if all you do with it is set the local variable to a global variable once? that kinda defeats the purpose of it.
with the waits inside your trigger thats bound to cause problems because everytime you click any door on your map that one is basically set to udg_Doors, but the same variable is used within your trigger after waits.

So first off:

Try A:
avoid using udg_Doors completely

Try B:
ALWAYS first set udg_Doors to r when you use it after a delay. That way you can still use GUI
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top