# [Trigger]Trigger Ignoring Conditions

Status
Not open for further replies.

#### tree-3

Level 2
Ok, I have got 2 near exactly the same triggers. One for firing cannons on the right side and one for firing them on the left side. However the one for firing cannons on the left side is not working. It is ignoring any conditions that use a variable in it.

Here is the working trigger

• Firing Rightside Cannons
• Events
• Unit - A unit Begins casting an ability
• Conditions
• (Ability being cast) Equal to Fire Right Cannons
• Actions
• Custom script: local integer udg_playernum
• Set playernum = ((Player number of (Triggering player)) - 1)
• Set Closest[playernum] = 751.00
• Set PlayersShip[playernum] = (Position of (Triggering unit))
• Set FaceAngle[playernum] = (Facing of (Triggering unit))
• Unit Group - Pick every unit in (Units within 750.00 of PlayersShip[playernum]) and do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Picked unit) Not equal to (Triggering unit)
• Then - Actions
• Set AngleBetweenShips[playernum] = (Angle from PlayersShip[playernum] to (Position of (Picked unit)))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• And - All (Conditions) are true
• Conditions
• AngleBetweenShips[playernum] Less than or equal to (FaceAngle[playernum] - 45.00)
• AngleBetweenShips[playernum] Greater than or equal to ((FaceAngle[playernum] - 180.00) + 45.00)
• Then - Actions
• Set TargetLoc[playernum] = (Distance between (Position of (Triggering unit)) and (Position of (Picked unit)))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• TargetLoc[playernum] Less than Closest[playernum]
• Then - Actions
• Set Closest[playernum] = TargetLoc[playernum]
• Set FireingTarg[playernum] = (Position of (Picked unit))
• Else - Actions
• Else - Actions
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• Closest[playernum] Less than 751.00
• Then - Actions
• For each (Integer CannonNumber[playernum]) from 0 to 3, do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• CannonFire[playernum] Equal to True
• Then - Actions
• Set CannonFire[playernum] = False
• Set Position[playernum] = (FireingTarg[playernum] offset by (Random real number between 0.00 and 150.00) towards (Random angle) degrees)
• Unit - Create 1 DummyCannon for Neutral Passive at PlayersShip[playernum] facing Default building facing degrees
• Set Cannon[playernum] = (Last created unit)
• Unit - Create 1 DummyTarget for Neutral Passive at Position[playernum] facing Default building facing degrees
• Set Target[playernum] = (Last created unit)
• Unit - Order Cannon[playernum] to Attack Target[playernum]
• Wait 0.70 seconds
• Unit - Order Target[playernum] to Human Mountain King - Thunder Clap
• Wait 0.50 seconds
• Unit - Remove Cannon[playernum] from the game
• Unit - Remove Target[playernum] from the game
• Set CannonFire[playernum] = True
• Else - Actions
• Else - Actions
• Game - Display to Player Group - Player 1 (Red) the text: No ship within rang...
Here is the trigger for Firing on the Leftside cannons

• Firing Leftside Cannons Copy
• Events
• Unit - A unit Begins casting an ability
• Conditions
• (Ability being cast) Equal to Fire Left Cannons
• Actions
• Custom script: local integer udg_playernum2
• Set playernum2 = (Player number of (Triggering player))
• Set Closest[playernum2] = 751.00
• Set PlayersShip[playernum2] = (Position of (Triggering unit))
• Set FaceAngle[playernum2] = (Facing of (Triggering unit))
• Unit Group - Pick every unit in (Units within 750.00 of PlayersShip[playernum2]) and do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Picked unit) Not equal to (Triggering unit)
• Then - Actions
• Game - Display to (All players) the text: (Name of (Picked unit))
• Set Integer = (Integer + 1)
• Game - Display to (All players) the text: (String(Integer))
• Game - Display to (All players) the text: (Picked Unit is + (Name of (Picked unit)))
• Set AngleBetweenShips[playernum2] = (Angle from PlayersShip[playernum2] to (Position of (Picked unit)))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• And - All (Conditions) are true
• Conditions
• AngleBetweenShips[playernum2] Greater than or equal to (FaceAngle[playernum2] + 45.00)
• AngleBetweenShips[playernum2] Greater than or equal to ((FaceAngle[playernum2] - 180.00) - 45.00)
• Then - Actions
• Set TargetLoc[playernum2] = (Distance between (Position of (Triggering unit)) and (Position of (Picked unit)))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• TargetLoc[playernum2] Less than Closest[playernum2]
• Then - Actions
• Set Closest[playernum2] = TargetLoc[playernum2]
• Set FireingTarg[playernum2] = (Position of (Picked unit))
• Else - Actions
• Else - Actions
• Else - Actions
• Game - Display to (All players) the text: No unit Picked
• Game - Display to (All players) the text: (String(Closest[playernum2]))
• Set Closest[playernum2] = 751.00
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• Closest[playernum2] Less than 750.00
• Then - Actions
• Game - Display to (All players) the text: (String(Closest[playernum2]))
• For each (Integer CannonNumber[playernum2]) from 0 to 3, do (Actions)
• Loop - Actions
• Game - Display to Player Group - Player 1 (Red) the text: ship within range o...
• Set Position[playernum2] = (FireingTarg[playernum2] offset by (Random real number between 0.00 and 150.00) towards (Random angle) degrees)
• Unit - Create 1 DummyCannon for Neutral Passive at PlayersShip[playernum2] facing Default building facing degrees
• Set Cannon[playernum2] = (Last created unit)
• Unit - Create 1 DummyTarget for Neutral Passive at Position[playernum2] facing Default building facing degrees
• Set Target[playernum2] = (Last created unit)
• Unit - Order Cannon[playernum2] to Attack Target[playernum2]
• Wait 0.70 seconds
• Unit - Order Target[playernum2] to Human Mountain King - Thunder Clap
• Wait 0.50 seconds
• Unit - Remove Cannon[playernum2] from the game
• Unit - Remove Target[playernum2] from the game
• Else - Actions
• Game - Display to Player Group - Player 1 (Red) the text: No ship within rang...

What is happening is that the trigger is ignoring the condition Closest[playernum2] Less then 750.00 (see extract below) and proceeding onto the Then Actions. I am completely lost in why this is happening. However, it only happens for variables not preset numbers. Any help would be appreciated

• Set Closest[playernum2] = 751.00
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• Closest[playernum2] Less than 750.00
• Then - Actions
• Game - Display to (All players) the text: (String(Closest[playernum2]))
• For each (Integer CannonNumber[playernum2]) from 0 to 3, do (Actions)
• Loop - Actions
• Game - Display to Player Group - Player 1 (Red) the text: ship within range o...
• Set Position[playernum2] = (FireingTarg[playernum2] offset by (Random real number between 0.00 and 150.00) towards (Random angle) degrees)
• Unit - Create 1 DummyCannon for Neutral Passive at PlayersShip[playernum2] facing Default building facing degrees
• Set Cannon[playernum2] = (Last created unit)
• Unit - Create 1 DummyTarget for Neutral Passive at Position[playernum2] facing Default building facing degrees
• Set Target[playernum2] = (Last created unit)
• Unit - Order Cannon[playernum2] to Attack Target[playernum2]
• Wait 0.70 seconds
• Unit - Order Target[playernum2] to Human Mountain King - Thunder Clap
• Wait 0.50 seconds
• Unit - Remove Cannon[playernum2] from the game
• Unit - Remove Target[playernum2] from the game
• Else - Actions
• Game - Display to Player Group - Player 1 (Red) the text: No ship within rang...

#### Reaper2008

Level 12
How can that be when you set it to 751 before this happens?

#### tree-3

Level 2
I have no idea why it is happening. It has completely confused me. I have attached a screenshot of what happens when I press the ability.

#### cedi

Level 10
“Shadowing” global variables with local variables no longer is possible.

That means: Since the new patch 1.24 isn't it possible to overwrith a global variable with a local variable... So this could be the problem.

cedi

#### Soga-

Level 7
• Set Closest[playernum2] = 751.00
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• Closest[playernum2] Less than 750.00

That's what Reaper is talking about. Look carefully at that - you're setting Closest[playernum2] to 751 immediately before checking if it's less than 750. Of course it will always ignore the condition!

#### cedi

Level 10
Dude, why should it ignore the condition? Because the variable is set before the condition? Ahh jeaa sure... No I think the problem is the shadowing of locals behind globals...

cedi

#### Soga-

Level 7
Well, not ignoring the condition, but evaluating it false every time, which is as good as ignoring it...

He's setting a variable to 751 and then immediately checking to see if it's less than 750. That means it will always evaluate to false.

#### cedi

Level 10
Dude, have you read his post? The trigger call each time the then actions, but that must be impossible, because 751 is higher then 750... And thats a strange bug. And I think the strange bug is because the globals overwritting...

cedi

#### Soga-

Level 7
Okay, I see what he was talking about now. Even though the actions should NOT be run, they are anyway. Yeah, I imagine it has to do with the global overshadowing the local variable.

Especially seeing as he declares a local variable with the udg prefix...

Status
Not open for further replies.

Replies
4
Views
1K
Replies
5
Views
1K
Replies
23
Views
11K
Replies
3
Views
558
Replies
5
Views
724