Fixing the trigger that changes a unit's position

Status
Not open for further replies.
Level 3
Joined
Feb 12, 2020
Messages
34
Hi there,

Some of you have already seen me fooling around in the discord channel. But as this requires quite some attention, I thought it would be better to make a seperate post on this matter.
To show you the issue, I first show what triggers I use and what variables are involved. I use GUI, I am an amateur user that's learning some things on the go.
I will pass each trigger one by one, paired with its variables. Thank you for reading, I hope you can help me out on this one, as I'm absolutely stuck.

In my 8-player auto-battler map, I have 8 spawning zones and 8 arena zones. Players prepare for duel by recruiting units. Then they fight a duel against another player.

-----
Trigger 1: the matchups | This trigger matches every player to a region. This functions well.
The first part of this trigger decides in which arena zone the player will fight. The seconds part is where you see ArenaminX/Y; this sets the coordinates to spawn the units in trigger 2.

Setup Arena Groups
  • Actions
    • -------- Reset these variables / Empty these player groups: --------
    • Set VariableSet AR_Counter = 0
    • Set VariableSet AR_Index = 1
    • Player Group - Remove all players from AR_RandomPlayers.
    • For each (Integer AR_Loop) from 1 to 4, do (Actions)
      • Loop - Actions
        • Player Group - Remove all players from AR_ArenaGroup[AR_Loop].
    • -------- --------
    • -------- Get a temporary reference to all of the active users: --------
    • Set VariableSet AR_RandomPlayers = (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing)).)
    • Set VariableSet AR_TotalPlayers = (Number of players in AR_RandomPlayers)
    • -------- --------
    • -------- Loop over the players and assign them an arena: --------
    • For each (Integer AR_Loop) from 1 to AR_TotalPlayers, do (Actions)
      • Loop - Actions
        • Set VariableSet AR_Counter = (AR_Counter + 1)
        • Set VariableSet AR_RandomPlayer = (Random player from AR_RandomPlayers)
        • Set VariableSet PN = (Player number of AR_RandomPlayer)
        • Player Group - Remove AR_RandomPlayer from AR_RandomPlayers.
        • Player Group - Add AR_RandomPlayer to AR_ArenaGroup[AR_Index]
        • -------- --------
        • -------- Player_ArenaIndex represents which AR_ArenaRegion the player will use: --------
        • Set VariableSet Player_ArenaIndex[PN] = AR_Loop
        • Set VariableSet Player_ArenaRegion[PN] = AR_ArenaRegion[AR_Loop]
        • Set VariableSet Player_ArenaPoint[PN] = AR_ArenaPoint[AR_Loop]
        • -------- --------
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • AR_Counter Equal to 2
          • Then - Actions
            • Set VariableSet AR_Counter = 0
            • Set VariableSet AR_Index = (AR_Index + 1)
          • Else - Actions
    • -------- Arena 1 --------
    • Set VariableSet ArenaRegion[1] = Arena1 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[1]] = 672.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[1]] = 3328.00
    • -------- Arena 2 --------
    • Set VariableSet ArenaRegion[2] = Arena2 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[2]] = 3392.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[2]] = 3328.00
    • -------- Arena 3 --------
    • Set VariableSet ArenaRegion[3] = Arena3 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[3]] = -576.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[3]] = 736.00
    • -------- Arena 4 --------
    • Set VariableSet ArenaRegion[4] = Arena4 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[4]] = 2112.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[4]] = 768.00
    • -------- Arena 5 --------
    • Set VariableSet ArenaRegion[5] = Arena5 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[5]] = -3136.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[5]] = -1792.00
    • -------- Arena 6 --------
    • Set VariableSet ArenaRegion[6] = Arena6 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[6]] = -448.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[6]] = -1792.00
    • -------- Arena 7 --------
    • Set VariableSet ArenaRegion[7] = Arena7 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[7]] = -4448.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[7]] = -4384.00
    • -------- Arena 8 --------
    • Set VariableSet ArenaRegion[8] = Arena8 <gen>
    • Set VariableSet ArenasMinX[Player_ArenaIndex[8]] = -1696.00
    • Set VariableSet ArenasMinY[Player_ArenaIndex[8]] = -4352.00
    • Trigger - Turn on Spawn <gen>
    • Trigger - Turn off (This trigger)

Trigger 2: spawning units | This trigger spawns units from the spawning zone in the correct arena zone, with the exact same position, using X/Y offset. This trigger functions well.
What you see in this trigger is the following;
Every unit in a tempgroup is selected. Then, the offset of X and Y compared to the X/Y of their spawning zone is calculated using 2 custom script for each X and Y.
Lastly, the point is set to be equal to this X/Y position. Now the units spawn on this point.
  • Player Group - Pick every player in (All players) and do (Actions)
    • Loop - Actions
      • Set VariableSet index = (Player number of (Picked player))
      • Set VariableSet tempgroup = (Units in SpawnRegion[index])
      • Unit Group - Pick every unit in tempgroup and do (Actions)
        • Loop - Actions
          • Custom script: set udg_XOffset = GetUnitX(GetEnumUnit()) - udg_SpawnsMinX[udg_index]
          • Custom script: set udg_YOffset = GetUnitY(GetEnumUnit()) - udg_SpawnsMinY[udg_index]
          • Set VariableSet tempPoint = (Point((ArenasMinX[index] + XOffset), (ArenasMinY[index] + YOffset)))
          • Unit - Create 1 (Unit-type of (Picked unit)) for (Player(index)) at tempPoint facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_tempPoint)
      • Custom script: call DestroyGroup(udg_tempgroup)

Trigger 3: turning the unit's position | This trigger does very curious things that are a mystery to me, hear me out.
For each arena zone, there is a middle point X and Y which are set. This trigger;
1. picks the units in the arena zones using temppgroup like in the previous trigger.
2. calculates anew offset, the distance between the unit and the middle point of the zrena zone for both X and Y.
3. Sets a new TempPoint that alters the position. The setTempPoint action changes the X and Y, using a formula used for turning things 90degrees around a point (the middle point of the arena zone): X=Y & Y=-X. This is what you see in this action.
4. Units get moved.

When I test alone, everything works fine. My units change their position by 90 degrees, just as intended.
When I test with another player however, all player's units swap their position twice instead of once, chnaging the unit position by 180 degrees. To me, it seems like something is stacking its action where it should not. My big question is: why is this happening, and what can I do to solve this?
  • Actions
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Set VariableSet index = (Player number of (Picked player))
        • Set VariableSet tempgroup = (Units in ArenaRegion[index])
        • Unit Group - Pick every unit in tempgroup and do (Actions)
          • Loop - Actions
            • Custom script: set udg_MidXOffset = GetUnitX(GetEnumUnit()) - udg_MidArenaX[Player_ArenaIndex[index]]
            • Custom script: set udg_MidYOffset = GetUnitY(GetEnumUnit()) - udg_MidArenaY[Player_ArenaIndex[index]]
            • Set VariableSet tempPoint = (Point((MidArenaX[(Player number of (Picked player))] + MidYOffset), (MidArenaY[(Player number of (Picked player))] - MidXOffset)))
            • Unit - Move (Picked unit) instantly to tempPoint
            • Custom script: call RemoveLocation(udg_tempPoint)
        • Custom script: call DestroyGroup(udg_tempgroup)

To fully fix this trigger, I need the units on arena 1,3,5 and 7 to change clockwise, where units in arena 2,4,6,8 need to change counterclockwise.

If you need more info before responding, please let me know.
Thanks, Kapharna
 
Last edited:
I suggest to use [trigger] tags to improve readability.

  • Events
    • Time - Every 0.25 seconds of game time
  • Conditions
  • Actions
    • -------- Reset these variables./ Empty these player groups: --------
    • Set VariableSet AR_Counter = 0
    • Set VariableSet AR_Index = 1
    • Player Group - Remove all players from AR_RandomPlayers.
    • For each (Integer AR_Loop) from 1 to 4, do (Actions)
    • Loop - Actions
      • Player Group - Remove all players from AR_ArenaGroup[AR_Loop]
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
I'm not fully understanding your method but these are things that stick out to me:
  • Why does Setup Arena Groups (SAG) run every 0.25 seconds but immediately turn itself off? Elapsed Game-time is the correct event.
  • In SAG the If-Block has no conditions so it will never evaluate the Then branch on any run through.
  • Even if the If-Block ran, the first time it did so all of the arena variables are set/initialized after it so either the trigger would crash or the data wouldn't be correct.
  • These lines in the 3rd trigger are written twice, and since the point is removed the second time the unit is moved it should get moved to (0,0) since you're giving it a null point:
    Unit - Move (Picked unit) instantly to tempPoint
    Custom script: call RemoveLocation(udg_tempPoint)
 
Level 3
Joined
Feb 12, 2020
Messages
34
I'm not fully understanding your method but these are things that stick out to me:
  • Why does Setup Arena Groups (SAG) run every 0.25 seconds but immediately turn itself off? Elapsed Game-time is the correct event.
  • In SAG the If-Block has no conditions so it will never evaluate the Then branch on any run through.
  • Even if the If-Block ran, the first time it did so all of the arena variables are set/initialized after it so either the trigger would crash or the data wouldn't be correct.
  • These lines in the 3rd trigger are written twice, and since the point is removed the second time the unit is moved it should get moved to (0,0) since you're giving it a null point:
    Unit - Move (Picked unit) instantly to tempPoint
    Custom script: call RemoveLocation(udg_tempPoint)
I edited the triggers both here and in the editor. Thanks for the heads up. I also added further explanation to what the triggers do.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
These lines in the 3rd tgrigger use [index] but it should be [udg_index] like the 2nd. Presumably this didn't throw a compile error because some globals block in your map has an integer variable named "index" chilling in it so it appears to be defined. Or the trigger those lines are in is actually disabled and something else is doing the rotation, but that seems even more unlikely than the random variable.

Custom script: set udg_MidXOffset = GetUnitX(GetEnumUnit()) - udg_MidArenaX[Player_ArenaIndex[index]]
Custom script: set udg_MidYOffset = GetUnitY(GetEnumUnit()) - udg_MidArenaY[Player_ArenaIndex[index]]
 
Level 3
Joined
Feb 12, 2020
Messages
34
These lines in the 3rd tgrigger use [index] but it should be [udg_index] like the 2nd. Presumably this didn't throw a compile error because some globals block in your map has an integer variable named "index" chilling in it so it appears to be defined. Or the trigger those lines are in is actually disabled and something else is doing the rotation, but that seems even more unlikely than the random variable.

Custom script: set udg_MidXOffset = GetUnitX(GetEnumUnit()) - udg_MidArenaX[Player_ArenaIndex[index]]
Custom script: set udg_MidYOffset = GetUnitY(GetEnumUnit()) - udg_MidArenaY[Player_ArenaIndex[index]]
O actually have the script error now 'Symbol not declared-undeclared identifier Player_ArenaIndex, on both lines.

I don't know what the line should be at this point.
(2 mins later)
Ok I rewrote it to be like this:
  • Actions
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Set VariableSet index = (Player number of (Picked player))
        • Set VariableSet tempgroup = (Units in ArenaRegion[index])
        • Unit Group - Pick every unit in tempgroup and do (Actions)
          • Loop - Actions
            • Custom script: set udg_MidXOffset = GetUnitX(GetEnumUnit()) - udg_MidArenaX[udg_index]
            • Custom script: set udg_MidYOffset = GetUnitY(GetEnumUnit()) - udg_MidArenaY[udg_index]
            • Set VariableSet tempPoint = (Point((MidArenaX[(Player number of (Picked player))] + MidYOffset), (MidArenaY[(Player number of (Picked player))] - MidXOffset)))
            • Unit - Move (Picked unit) instantly to tempPoint
            • Custom script: call RemoveLocation(udg_tempPoint)
        • Custom script: call DestroyGroup(udg_tempgroup)
    • Trigger - Turn off (This trigger)

See image for the results. What did I do wrong compared to trigger 2, which works perfectly.
 

Attachments

  • What is happening.png
    What is happening.png
    6.5 MB · Views: 18
Level 3
Joined
Feb 12, 2020
Messages
34
Oh. My Gosh. I found the fix guys.

It turns out, the Player Group - Pick every player action stacks the action for all players. I removed the fucntion as it served no purpose, started the action from unit group and now it functions like it should haha.
So glad.

This is solved, wise lesson
 
Status
Not open for further replies.
Top