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

[Solved] Trigger Running Despite Being Turned Off

Status
Not open for further replies.
Level 37
Joined
Jul 22, 2015
Messages
3,485
I'm making what I call a "Region Teleportation System" for someone so that they can easily make regions from the Region Palette, and then connect them via this system without having to create a seperate trigger for every single region. To avoid an infinite loop, I turn the trigger off, move the unit to the appropriate region, and then I turn the trigger back on. However, it seems to not work because the unit still gets teleported back and forth.

Here is how the regions are connected:

  • RegSys List
    • Events
    • Conditions
    • Actions
      • Set RegSys_AddRegion1 = A1 <gen>
      • Set RegSys_AddRegion2 = A2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
      • -------- --------
      • Set RegSys_AddRegion1 = B1 <gen>
      • Set RegSys_AddRegion2 = B2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
      • -------- --------
      • Set RegSys_AddRegion1 = C1 <gen>
      • Set RegSys_AddRegion2 = C2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
      • -------- --------
      • Set RegSys_AddRegion1 = D1 <gen>
      • Set RegSys_AddRegion2 = D2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
  • RegSys Add
    • Events
    • Conditions
    • Actions
      • -------- child keys for Region Teleportation System --------
      • -------- 0 - center of region to teleport to --------
      • -------- 1 - facing angle --------
      • -------- --------
      • -------- --------
      • Custom script: local region region1 = CreateRegion()
      • Custom script: local region region2 = CreateRegion()
      • Custom script: call RegionAddRect(region1, udg_RegSys_AddRegion1)
      • Custom script: call RegionAddRect(region2, udg_RegSys_AddRegion2)
      • -------- region 1 --------
      • Custom script: set udg_RegSys_RegId = GetHandleId(region1)
      • Hashtable - Save Handle Of(Center of RegSys_AddRegion2) as 0 of RegSys_RegId in RegSys_Hash
      • Hashtable - Save RegSys_AddFacingAngle2 as 1 of RegSys_RegId in RegSys_Hash
      • -------- region 2 --------
      • Custom script: set udg_RegSys_RegId = GetHandleId(region2)
      • Hashtable - Save Handle Of(Center of RegSys_AddRegion1) as 0 of RegSys_RegId in RegSys_Hash
      • Hashtable - Save RegSys_AddFacingAngle1 as 1 of RegSys_RegId in RegSys_Hash
      • -------- --------
      • Custom script: call TriggerRegisterEnterRegion(udg_RegSys_TRIGGER_MOVE_UNIT, region1, null)
      • Custom script: call TriggerRegisterEnterRegion(udg_RegSys_TRIGGER_MOVE_UNIT, region2, null)
      • Custom script: set region1 = null
      • Custom script: set region2 = null
      • -------- --------
      • -------- resetting global variables --------
      • Set RegSys_AddRegion1 = No region
      • Set RegSys_AddRegion2 = No region
      • Set RegSys_AddFacingAngle1 = 0.00
      • Set RegSys_AddFacingAngle2 = 0.00
Here is the trigger that moves the unit to the appropriate region:

  • RegSys Move Unit
    • Events
    • Conditions
    • Actions
      • -------- child keys for Region Teleportation System --------
      • -------- 0 - center of region to teleport to --------
      • -------- 1 - facing angle --------
      • -------- --------
      • -------- --------
      • -------- moving unit to connected region --------
      • Trigger - Turn off RegSys_TRIGGER_MOVE_UNIT
      • Custom script: set udg_RegSys_RegId = GetHandleId(GetTriggeringRegion())
      • Unit - Move (Triggering unit) instantly to (Load 0 of RegSys_RegId in RegSys_Hash), facing (Load 1 of RegSys_RegId from RegSys_Hash) degrees
      • Trigger - Turn on RegSys_TRIGGER_MOVE_UNIT
Adding a 0.00 second wait timer before I turn the trigger back on fixes it. However, I don't understand why turning the trigger off and on doesn't prevent the loop. I have already tried using SetUnitX() and SetUnitY(), but I still get the same issue.


EDIT - Okay so I added a debug message that prints the triggering unit's X/Y to ensure that the unit was at the location before turning the trigger back on. The messages confirm that the unit is in fact there before the trigger is turned back on.


EDIT 2 - GetHandleId(udg_RegSys_TRIGGER_MOVE_UNIT) & GetHandleId(GetTriggeringTrigger()) both have the same values.
 
Last edited:
I'm making what I call a "Region Teleportation System" for someone so that they can easily make regions from the Region Palette, and then connect them via this system without having to create a seperate trigger for every single region. To avoid an infinite loop, I turn the trigger off, move the unit to the appropriate region, and then I turn the trigger back on. However, it seems to not work because the unit still gets teleported back and forth.

Here is how the regions are connected:

  • RegSys List
    • Events
    • Conditions
    • Actions
      • Set RegSys_AddRegion1 = A1 <gen>
      • Set RegSys_AddRegion2 = A2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
      • -------- --------
      • Set RegSys_AddRegion1 = B1 <gen>
      • Set RegSys_AddRegion2 = B2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
      • -------- --------
      • Set RegSys_AddRegion1 = C1 <gen>
      • Set RegSys_AddRegion2 = C2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
      • -------- --------
      • Set RegSys_AddRegion1 = D1 <gen>
      • Set RegSys_AddRegion2 = D2 <gen>
      • Set RegSys_AddFacingAngle1 = 270.00
      • Set RegSys_AddFacingAngle2 = 90.00
      • Trigger - Run RegSys_TRIGGER_CONNECT_REGIONS (ignoring conditions)
  • RegSys Add
    • Events
    • Conditions
    • Actions
      • -------- child keys for Region Teleportation System --------
      • -------- 0 - center of region to teleport to --------
      • -------- 1 - facing angle --------
      • -------- --------
      • -------- --------
      • Custom script: local region region1 = CreateRegion()
      • Custom script: local region region2 = CreateRegion()
      • Custom script: call RegionAddRect(region1, udg_RegSys_AddRegion1)
      • Custom script: call RegionAddRect(region2, udg_RegSys_AddRegion2)
      • -------- region 1 --------
      • Custom script: set udg_RegSys_RegId = GetHandleId(region1)
      • Hashtable - Save Handle Of(Center of RegSys_AddRegion2) as 0 of RegSys_RegId in RegSys_Hash
      • Hashtable - Save RegSys_AddFacingAngle2 as 1 of RegSys_RegId in RegSys_Hash
      • -------- region 2 --------
      • Custom script: set udg_RegSys_RegId = GetHandleId(region2)
      • Hashtable - Save Handle Of(Center of RegSys_AddRegion1) as 0 of RegSys_RegId in RegSys_Hash
      • Hashtable - Save RegSys_AddFacingAngle1 as 1 of RegSys_RegId in RegSys_Hash
      • -------- --------
      • Custom script: call TriggerRegisterEnterRegion(udg_RegSys_TRIGGER_MOVE_UNIT, region1, null)
      • Custom script: call TriggerRegisterEnterRegion(udg_RegSys_TRIGGER_MOVE_UNIT, region2, null)
      • Custom script: set region1 = null
      • Custom script: set region2 = null
      • -------- --------
      • -------- resetting global variables --------
      • Set RegSys_AddRegion1 = No region
      • Set RegSys_AddRegion2 = No region
      • Set RegSys_AddFacingAngle1 = 0.00
      • Set RegSys_AddFacingAngle2 = 0.00
Here is the trigger that moves the unit to the appropriate region:

  • RegSys Move Unit
    • Events
    • Conditions
    • Actions
      • -------- child keys for Region Teleportation System --------
      • -------- 0 - center of region to teleport to --------
      • -------- 1 - facing angle --------
      • -------- --------
      • -------- --------
      • -------- moving unit to connected region --------
      • Trigger - Turn off RegSys_TRIGGER_MOVE_UNIT
      • Custom script: set udg_RegSys_RegId = GetHandleId(GetTriggeringRegion())
      • Unit - Move (Triggering unit) instantly to (Load 0 of RegSys_RegId in RegSys_Hash), facing (Load 1 of RegSys_RegId from RegSys_Hash) degrees
      • Trigger - Turn on RegSys_TRIGGER_MOVE_UNIT
Adding a 0.00 second wait timer before I turn the trigger back on fixes it. However, I don't understand why turning the trigger off and on doesn't prevent the loop. I have already tried using SetUnitX() and SetUnitY(), but I still get the same issue.


EDIT - Okay so I added a debug message that prints the triggering unit's X/Y to ensure that the unit was at the location before turning the trigger back on. The messages confirm that the unit is in fact there before the trigger is turned back on.


EDIT 2 - GetHandleId(udg_RegSys_TRIGGER_MOVE_UNIT) & GetHandleId(GetTriggeringTrigger()) both have the same values.


I once ran into the same issue when creating a tunnel system. I would guess that the enter region event is synchronous. So for my workaround, (which I'm not sure if it is applicable), I had to check the order id of the unit if it is trying to get to the other end of the tunnel, checking if the unit is in a filter group and letting the trigger that registers the enter region event check the entering unit if it is eligible for transportation. I had another trigger to detect when the unit would leave the region so that it would be removed from the group.

Going back to the event, it is synchronous, which means that it is happening in the thread and not in a new thread. However, the presence of triggerconditions and triggeractions create a new thread every time they are fired. This means that the type of bug you're experiencing is an infinite loop, which is why an asynchronous thread such as a timer expiring in 0.00 seconds works for the system.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Thanks, MyPad.

I went ahead and used your method with the filter group and it works perfectly. I actually didn't have to use a "leaves region" event to get it to work.

  • RegSys Move Unit
    • Events
    • Conditions
    • Actions
      • -------- child keys for Region Teleportation System --------
      • -------- 0 - center of region to teleport to --------
      • -------- 1 - facing angle --------
      • -------- --------
      • -------- --------
      • Set RegSys_Unit = (Triggering unit)
      • -------- checking if unit is in the region because they were teleported by another region --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (RegSys_Unit is in RegSys_DoNotMove) Equal to False
        • Then - Actions
          • -------- unit is not here because of another region --------
          • -------- --------
          • Custom script: set udg_RegSys_RegId = GetHandleId(GetTriggeringRegion())
          • Unit - Move RegSys_Unit instantly to (Load 0 of RegSys_RegId in RegSys_Hash), facing (Load 1 of RegSys_RegId from RegSys_Hash) degrees
          • Unit Group - Add RegSys_Unit to RegSys_DoNotMove
        • Else - Actions
          • -------- unit is here because of a region --------
          • -------- --------
          • Unit Group - Remove RegSys_Unit from RegSys_DoNotMove
 
Status
Not open for further replies.
Top