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

Portal Gun item - Variable for location references two points at the same time + random game crashes for unknown reason

Status
Not open for further replies.
Level 1
Joined
Feb 3, 2021
Messages
2
Hi all,

I am attempting to create a Portal Gun item for my single player adventure map. The idea of the item is pretty much the same as the portal gun in Portal game series: User can point to a location, create a portal which connects to previously created portal like a Waygate. Only 2 portals ever exist at the same time, old one gets removed as new one is created. Not too complicated, eh?

Well, I have been struggling with really perplexing bugs with the trigger system and now I have to resort to asking you guys for help. If some puzzle-loving, good-hearted soul is interested, I’d appreciate any help. I've heavily commented on my triggers so it would be easier for you people to help me troubleshoot this.

Be warned, this is a long post. I’ve tried multiple things to fix my own issues, and I go through my thoughts to help you read my GUI code.

Basically I have a couple of variables for referencing the locations of the two portals. These locations get updated as the portals are moved: the new portal is set up at the point referenced by the variable. Later on as units attempt to move through the portals, the location variables are used to compare distances and to actually teleport the units. The main issue with this is that both of the variables seemingly reference MULTIPLE locations, even though I thought that would be impossible. The portals get created with no issues, and my debug messages confirm that the variable was changed. However, as I use another debug trigger to ping the map to show the location of the points, they are elsewhere, even though no trigger should have changed them or reset them (I’d say they are at map centre, but I have not confirmed this). The teleportation system also does not work.

If I don’t use the variables and instead just reference points via the GUI function “Location of unit”, the system just works. But then the code leaks point references and takes a lot more processing power. Is this even an issue in a single player map?

The test map also has started to crash occasionally as I attempt to use the portal gun to create a new portal, but I have no idea why. To me it seems that I have no infinite loops, and I should be far away still from any memory limits. Could the crashes maybe be related to using the test map feature of the map editor? That’d be easy to solve at least...

Here are the triggers. I’m using version 1.30 so I can still create and play custom campaigns. This is something I can not easily give up with my map, as the design involves moving from map to map…

This one just enables the entire system:
  • PG Init
    • Events
    • Conditions
    • Actions
      • -------- game has a tendency to crash sometimes if portal gun triggers are in game. --------
      • -------- I don't know the reason for crashes, as to me there seems to be no significant leaks or infinite loops --------
      • -------- Crashes are seemingly random, I've been unable to replicate them. The game just works sometimes, sometimes it doesn't --------
      • -------- Setup variables, hide unusable portals --------
      • -------- portals need to be preplaced, GUI allows only "entering range" event for preplaced units --------
      • Set PG_Portal1 = Shimmering Portal 0011 <gen>
      • Set PG_Portal2 = Shimmering Portal 0012 <gen>
      • Set PG_Portal1Location = (Position of PG_Portal1)
      • Set PG_Portal2Location = (Position of PG_Portal2)
      • -------- Ownership change for security, no visibility or aggro etc. relating to portals --------
      • Unit - Change ownership of PG_Portal1 to Neutral Passive and Change color
      • Unit - Change ownership of PG_Portal2 to Neutral Passive and Change color
      • Unit - Hide PG_Portal1
      • Unit - Hide PG_Portal2
The item itself is based on Tiny Castle, but it builds dummy portals. The dummy portal is categorized as a building. The real portal is a modified footman, in order to allow it to be turned to face different angles. I used two units as just using one did not work.
When the item is acquired:
  • PG Setup User
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Portal Gun
    • Actions
      • -------- As a new unit acquires the PG item, set that unit as the user. PG user unit location is used for setting portal facings --------
      • Set PG_User = (Triggering unit)
      • -------- Only units belonging to the same player as the user can move through the portals. This may be changed here --------
      • Set PG_OwnerOfUser = (Owner of PG_User)
      • -------- Allow creation of portals only after a user has been set up --------
      • Trigger - Turn on PG New Portal <gen>
When the item is used, the dummy building gets removed and the location gets used to move the preplaced portal units around. The trigger waits until a second portal is created before it enables the teleportation system. After that it just takes turns moving the first and the second portals around to desired locations.

This trigger is one of the most troublesome ones. I manage to make it work if I DON'T use variables to reference points (PG_Portal1Location and PG_Portal2Location) and instead just call "Position of unit Shimmering portal 0011/0012" every time. Debug messages confirm that the if-else structure functions correctly, and that the location variables DO MOVE around. However when I fire my debug trigger (found below later), it pings totally different locations.

I think I could make this entire trigger shorter and nicer looking, but first I'd just love to see it work at all, even though this approach is not the most efficient.
  • PG New Portal
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Shimmering Portal (dummy)
    • Actions
      • -------- Record required points as temp values --------
      • Set Temp_location = (Position of (Constructing structure))
      • Set Temp_location2 = (Position of PG_User)
      • -------- remove dummy --------
      • Unit - Remove (Triggering unit) from the game
      • -------- Moving portals is currently a long, semi-repeating if-then-else limbo, as I am a shit coder. It works with references to preplaced unit locations, but not with point variables --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • PG_NumOfPortals Equal to 0
        • Then - Actions
          • -------- If portal number is 0, create first portal --------
          • -------- Update portal location, item user location, portal angle and portal number --------
          • Set PG_Portal1Location = Temp_location
          • Set PG_NumOfPortals = 1
          • Set PG_LastCreated = 1
          • Set PG_Portal1Angle = (Angle from PG_Portal1Location to Temp_location2)
          • -------- Debug Messages --------
          • Game - Display to (All players) the text: 1
          • Game - Display to (All players) the text: (Portal1Location: + ((String((X of PG_Portal1Location))) + (String((Y of PG_Portal1Location)))))
          • Game - Display to (All players) the text: (PG_NumOfPortals: + (String(PG_NumOfPortals)))
          • Game - Display to (All players) the text: (PG_LastCreated: + (String(PG_LastCreated)))
          • -------- Place teleport to specified location and unhide --------
          • Unit - Move PG_Portal1 instantly to PG_Portal1Location
          • Unit - Make PG_Portal1 face PG_Portal1Angle over 0.00 seconds
          • Unit - Unhide PG_Portal1
          • -------- Play a snappy portal birth animation --------
          • Animation - Change PG_Portal1's animation speed to 300.00% of its original speed
          • Animation - Play PG_Portal1's birth animation
          • -------- Prepare reset to regular stand animation, needs accurate timer --------
          • Animation - Queue PG_Portal1's stand animation
          • Countdown Timer - Start PG_animationTimer1 as a One-shot timer that will expire in 3.00 seconds
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • PG_NumOfPortals Equal to 1
            • Then - Actions
              • -------- If portal number is 1, create second portal --------
              • -------- Update portal location, item user location, portal angle and portal number --------
              • Set PG_Portal2Location = Temp_location
              • Set PG_NumOfPortals = 2
              • Set PG_LastCreated = 2
              • Set PG_Portal2Angle = (Angle from PG_Portal2Location to Temp_location2)
              • -------- Debug Messages --------
              • Game - Display to (All players) the text: 2
              • Game - Display to (All players) the text: (Portal2Location: + ((String((X of PG_Portal2Location))) + (String((Y of PG_Portal2Location)))))
              • Game - Display to (All players) the text: (PG_NumOfPortals: + (String(PG_NumOfPortals)))
              • Game - Display to (All players) the text: (PG_LastCreated: + (String(PG_LastCreated)))
              • -------- Place teleport to specified location and unhide --------
              • Unit - Move PG_Portal2 instantly to PG_Portal2Location
              • Unit - Make PG_Portal2 face PG_Portal2Angle over 0.00 seconds
              • Unit - Unhide PG_Portal2
              • -------- Play a snappy portal birth animation --------
              • Animation - Change PG_Portal2's animation speed to 300.00% of its original speed
              • Animation - Play PG_Portal2's birth animation
              • -------- Prepare reset to regular stand animation, needs accurate timer --------
              • Animation - Queue PG_Portal2's stand animation
              • Countdown Timer - Start PG_animationTimer2 as a One-shot timer that will expire in 3.00 seconds
              • -------- There are now two portals, turn on teleportation system --------
              • Trigger - Turn on PG Unit wants to teleport from 1 to 2 <gen>
              • Trigger - Turn on PG Unit wants to teleport from 2 to 1 <gen>
              • Trigger - Turn on PG Unit no longer wants to teleport <gen>
              • Trigger - Turn on PG Move Units from 1 to 2 <gen>
              • Trigger - Turn on PG Move Units from 2 to 1 <gen>
              • -------- Debug Messages --------
              • Game - Display to (All players) the text: teleportation trigg...
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • PG_LastCreated Equal to 2
                • Then - Actions
                  • -------- If portal number is not 0 or 1 and portal2 was the previous portal, move portal 1 --------
                  • -------- Update portal 1 location, item user location, portal 1 angle and portal number --------
                  • Set PG_Portal1Location = Temp_location
                  • Set PG_NumOfPortals = 2
                  • Set PG_LastCreated = 1
                  • Set PG_Portal1Angle = (Angle from PG_Portal1Location to Temp_location2)
                  • -------- Debug Messages --------
                  • Game - Display to (All players) the text: 3
                  • Game - Display to (All players) the text: (Portal1Location: + ((String((X of PG_Portal1Location))) + (String((Y of PG_Portal1Location)))))
                  • Game - Display to (All players) the text: (PG_NumOfPortals: + (String(PG_NumOfPortals)))
                  • Game - Display to (All players) the text: (PG_LastCreated: + (String(PG_LastCreated)))
                  • -------- Place teleport to specified location --------
                  • Unit - Move PG_Portal1 instantly to PG_Portal1Location
                  • Unit - Make PG_Portal1 face PG_Portal1Angle over 0.00 seconds
                  • -------- Play a snappy portal birth animation --------
                  • Animation - Change PG_Portal1's animation speed to 300.00% of its original speed
                  • Animation - Play PG_Portal1's birth animation
                  • -------- Prepare reset to regular stand animation, needs accurate timer --------
                  • Animation - Queue PG_Portal1's stand animation
                  • Countdown Timer - Start PG_animationTimer1 as a One-shot timer that will expire in 3.00 seconds
                • Else - Actions
                  • -------- If portal number is not 0 or 1 and portal1 was the previous portal, move portal 2 --------
                  • -------- Update portal 2 location, item user location, portal 2 angle and portal number --------
                  • Set PG_Portal2Location = Temp_location
                  • Set PG_NumOfPortals = 2
                  • Set PG_LastCreated = 2
                  • Set PG_Portal2Angle = (Angle from PG_Portal2Location to Temp_location2)
                  • -------- Place teleport to specified location --------
                  • Unit - Move PG_Portal2 instantly to PG_Portal2Location
                  • Unit - Make PG_Portal2 face PG_Portal2Angle over 0.00 seconds
                  • -------- Debug Messages --------
                  • Game - Display to (All players) the text: 4
                  • Game - Display to (All players) the text: (Portal2Location: + ((String((X of PG_Portal2Location))) + (String((Y of PG_Portal2Location)))))
                  • Game - Display to (All players) the text: (PG_NumOfPortals: + (String(PG_NumOfPortals)))
                  • Game - Display to (All players) the text: (PG_LastCreated: + (String(PG_LastCreated)))
                  • -------- Play a snappy portal birth animation --------
                  • Animation - Change PG_Portal2's animation speed to 300.00% of its original speed
                  • Animation - Play PG_Portal2's birth animation
                  • -------- Prepare reset to regular stand animation, needs accurate timer --------
                  • Animation - Queue PG_Portal2's stand animation
                  • Countdown Timer - Start PG_animationTimer2 as a One-shot timer that will expire in 3.00 seconds
      • Custom script: call RemoveLocation(udg_Temp_location)
      • Custom script: call RemoveLocation(udg_Temp_location2)
Here's the trigger for setting up units that want to use the portals. I'd prefer the system to mirror the behaviour of Waygates, as that would make it familiar and easy to understand to most players. I have tried using the system of buildable waygates, but that system did not work (the waygate ability did not fire). I have also tried to use regions, but the "move region" action apparently does not move the BORDERS of a region, which I need to check if a unit is close to the portal or not.

In the end I resorted to using two preplaced portals, which I hide before they get used and then just move those two around and play some animations. This did work as long as I did not use point variables, but referencing unit location repeatedly is inefficient and leaks points. There's also the issue of crashing due to unknown reasons.

The system works by adding any units that are ordered to move to either portal to a unit group, which is then a condition for teleport in the two later triggers where a unit gets close to a portal. This way a unit can hang around the portal or move close to the portal and not get teleported (like Waygates work). Units only get teleported if the player commands them to move through the portal. The triggers repeat the move order with a slight offset, as just asking a unit to follow the portal would not move it close enough.

I currently use multiple triggers instead of one for easier troubleshoot, even though currently I have to repeat a lot of myself in the code.
  • PG Unit wants to teleport from 1 to 2
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Target unit of issued order) Equal to PG_Portal1
    • Actions
      • -------- "PG unit wants to teleport" 1 and 2 are two separate ones. I had previously only one trigger with both portals as references for the trigger event, but the teleportation system did not work. --------
      • -------- Set up the variable referencing the ordered unit. Triggering unit does not work here for some reason. --------
      • Set PG_OrderedToPortal = (Ordered unit)
      • -------- Debug messages --------
      • Game - Display to (All players) the text: (PG_OrderedToPortal: + (Name of PG_OrderedToPortal))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of PG_OrderedToPortal) Equal to PG_OwnerOfUser
        • Then - Actions
          • -------- First, the ownership of unit is confirmed, although the portals should be safe from random AI targeting as they belong to Neutral Passive (see init trigger) --------
          • -------- Then check if the ordered unit is already within the transportation range of the clicked teleport. --------
          • -------- Should use temp_location and portal location variables for comparison, as other location references leak --------
          • -------- the teleportation is bugged if the preplaced unit location is not referenced via the function "Position of unit". Variable does not work for some reason --------
          • Set Temp_location = (Position of PG_OrderedToPortal)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_location and PG_Portal1Location) Less than or equal to 100.00
            • Then - Actions
              • -------- Move unit instantly if already close to portal. this should be the same as in triggers "PG Move Units" --------
              • Unit - Move PG_OrderedToPortal instantly to PG_Portal2Location
              • Custom script: call RemoveLocation(udg_Temp_location)
            • Else - Actions
              • -------- If unit is not in range, order to move within teleport range, add to units wanting to teleport --------
              • Custom script: call RemoveLocation(udg_Temp_location)
              • -------- PG_UnitsToPortal1 is for units ordered to move to portal 1 (to teleport to portal 2), and vice versa --------
              • Unit Group - Add PG_OrderedToPortal to PG_UnitsToPortal1
              • Trigger - Turn off PG Unit no longer wants to teleport <gen>
              • Unit - Order PG_OrderedToPortal to Move To (PG_Portal1Location offset by 1.00 towards 0.00 degrees)
              • Trigger - Turn on PG Unit no longer wants to teleport <gen>
        • Else - Actions
Here's the second trigger for portal 2:
  • PG Unit wants to teleport from 2 to 1
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Target unit of issued order) Equal to PG_Portal2
    • Actions
      • -------- These triggers are two separate ones. I had previously only one trigger with both portals as references for the trigger event, but the teleportation system did not work. --------
      • -------- Set up the variable referencing the ordered unit. Triggering unit does not work here for some reason. --------
      • Set PG_OrderedToPortal = (Ordered unit)
      • Game - Display to (All players) the text: (PG_OrderedToPortal: + (Name of PG_OrderedToPortal))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of PG_OrderedToPortal) Equal to PG_OwnerOfUser
        • Then - Actions
          • -------- First, the ownership of unit is confirmed, although the portals should be safe from random AI targeting as they belong to Neutral Passive (see init trigger) --------
          • -------- Then check if the ordered unit is already within the transportation range of the clicked teleport. --------
          • -------- Should use temp_location and portal location variables for comparison, as other location references leak --------
          • -------- the teleportation is bugged if the preplaced unit location is not referenced via the function "Position of unit". Variable does not work for some reason --------
          • Set Temp_location = (Position of PG_OrderedToPortal)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_location and PG_Portal2Location) Less than or equal to 100.00
            • Then - Actions
              • -------- Move unit instantly if already close to portal. this should be the same as in triggers "PG Move Units" --------
              • Unit - Move PG_OrderedToPortal instantly to PG_Portal1Location
              • Custom script: call RemoveLocation(udg_Temp_location)
            • Else - Actions
              • -------- If unit is not in range, order to move within teleport range, add to units wanting to teleport --------
              • Custom script: call RemoveLocation(udg_Temp_location)
              • -------- PG_UnitsToPortal1 is for units ordered to move to portal 1 (to teleport to portal 2), and vice versa --------
              • Unit Group - Add PG_OrderedToPortal to PG_UnitsToPortal2
              • Trigger - Turn off PG Unit no longer wants to teleport <gen>
              • Unit - Order PG_OrderedToPortal to Move To (PG_Portal2Location offset by (1.00, 0.00))
              • Trigger - Turn on PG Unit no longer wants to teleport <gen>
        • Else - Actions
This trigger removes units from the unit groups if they are ordered to do something else. According to my knowledge, this trigger works fine, though I'm not a Pro at this. I don't remove the unit groups in any trigger, as they keep being reused, but it should not leak as there are only ever two unit groups, one for moving to portal 1 (to teleport to 2) and another for moving to portal 2 (to teleport to 1).
  • PG Unit no longer wants to teleport
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • ((((Triggering unit) is in PG_UnitsToPortal1) Equal to True) and ((Target unit of issued order) Not equal to PG_Portal1)) or ((((Triggering unit) is in PG_UnitsToPortal2) Equal to True) and ((Target unit of issued order) Not equal to PG_Portal2))
    • Actions
      • -------- If unit in wanting to teleport from 1 to 2 is ordered to somewhere else than portal 1, remove said unit from group --------
      • -------- If unit in wanting to teleport from 2 to 1 is ordered to somewhere else than portal 2, remove said unit from group --------
      • -------- Setting up variable only for leak prevention, if a point is referenced in the event of this trigger --------
      • Set Temp_location = (Target point of issued order)
      • Custom script: call RemoveLocation(udg_Temp_location)
      • -------- PG_UnitsToPortal1 is for units ordered to move to portal 1 (to teleport to portal 2), and vice versa --------
      • Unit Group - Remove (Triggering unit) from PG_UnitsToPortal1
      • Unit Group - Remove (Triggering unit) from PG_UnitsToPortal2
      • Game - Display to (All players) the text: (No longer wants to teleport: + (Name of (Triggering unit)))
These two triggers only reset portal animation speed. The portal birth animation at 100% speed takes almost 10 seconds, so I triple the speed and reset it after the timer expires.

I could make the portal system more beautiful by adding effects/sounds and tweaking animation times etc. but honestly I think I should at least make it work first...
  • PG Animation Reset 1
    • Events
      • Time - PG_animationTimer1 expires
    • Conditions
    • Actions
      • Animation - Change PG_Portal1's animation speed to 100.00% of its original speed
Second one:
  • PG Animation Reset 2
    • Events
      • Time - PG_animationTimer2 expires
    • Conditions
    • Actions
      • Animation - Change PG_Portal2's animation speed to 100.00% of its original speed
These two triggers move units when they were too far away initially from the portal, but they now get close to the portal. The condition checks that the unit has been ordered to teleport by the player. Otherwise no units get teleported. These two were combined as well into one trigger, but the system did not work. These triggers work in my map when I replace the references to "PG_Portal1Location/PG_Portal2Location" with function calls getting the position of unit "shimmering portal 0011/0012". I have no clue as to why.
  • PG Move Units from 1 to 2
    • Events
      • Unit - A unit comes within 100.00 of Shimmering Portal 0011 <gen>
    • Conditions
      • ((Triggering unit) is in PG_UnitsToPortal1) Equal to True
    • Actions
      • -------- As unit ordered to the portal gets close enough to said portal, teleport unit --------
      • -------- Units that just move close to portal won't get moved --------
      • Unit - Move (Triggering unit) instantly to PG_Portal2Location
      • Wait 0.00 seconds
      • -------- To make unit just stop at the other portal, order it to move just a bit forward --------
      • Unit - Order (Triggering unit) to Move To (PG_Portal2Location offset by 200.00 towards PG_Portal2Angle degrees)
      • -------- This last action does not work at all for some reason. --------
      • -------- Even if teleportation works (with references to "location of unit" instead of "PG_PortalXLocation" variable), units get ordered behind the portal or to the other portal. --------
      • -------- The PG portal angle and portal location variables break the entire portal system for some unknown reason --------
The second trigger for the other portal:
  • PG Move Units from 2 to 1
    • Events
      • Unit - A unit comes within 100.00 of Shimmering Portal 0012 <gen>
    • Conditions
      • ((Triggering unit) is in PG_UnitsToPortal2) Equal to True
    • Actions
      • -------- As unit ordered to the portal gets close enough to said portal, teleport unit --------
      • -------- Units that just move close to portal won't get moved --------
      • Unit - Move (Triggering unit) instantly to PG_Portal1Location
      • Wait 0.00 seconds
      • -------- To make unit just stop at the other portal, order it to move just a bit forward --------
      • Unit - Order (Triggering unit) to Move To (PG_Portal1Location offset by 200.00 towards PG_Portal1Angle degrees)
      • -------- This last action does not work at all for some reason. --------
      • -------- Even if teleportation works (with references to "location of unit" instead of "PG_PortalXLocation" variable), units get ordered behind the portal or to the other portal. --------
      • -------- The PG portal angle and portal location variables break the entire portal system for some unknown reason --------
And finally my debugger, which may in itself too be bugged, but I don't think so:
  • spell out variables
    • Events
      • Player - Player 1 (Red) types a chat message containing pg variables as An exact match
    • Conditions
    • Actions
      • Cinematic - Ping minimap for (All players) at PG_Portal1Location for 5.00 seconds
      • Cinematic - Ping minimap for (All players) at PG_Portal2Location for 5.00 seconds
      • Game - Display to (All players) the text: (PG_User: + (Name of PG_User))
      • Game - Display to (All players) the text: (PG_NumOfPortals: + (String(PG_NumOfPortals)))
Thank you for reading this far.

As you hopefully can see, I've tried multiple different approaches, and none of them gives me the behaviour I want, is stable AND does not leak. I'm open to any suggestions, although I must warn you that I need handholding with JASS. I only know GUI and Google-fu...

Map posted below, there are some test spells there too. But the problem can't be that I'm approaching the "script limit" or whatever-one-calls-that, can it?

I'm a very inexperienced scripter, and even though I could just leave the custom spells from my map, this Portal Gun item is integral to the design and I need it to work. I'll gladly answer any questions.

If someone actually wants to use my scripts, feel free. If you can get them to work...
 

Attachments

  • ability test.w3x
    198.1 KB · Views: 13

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
In PG New Portal you destroy the location referenced by udg_Temp_location while you still intend to use it in the future as a portal position. As such the other triggers that try to access it get an invalid, null like, location which represents the centre of the map.

Locations are complex objects that are referenced. A location value is a reference to a location object. Multiple location variables can reference the same location object. Assigning a location to a location variable assigns its reference, it does not make a copy of the location object and assign a new reference. If that location object is destroyed, then all variables referencing that location object now reference a destroyed location which will evaluate similar to a null location.
I have also tried to use regions, but the "move region" action apparently does not move the BORDERS of a region, which I need to check if a unit is close to the portal or not.
This is because you are not modifying the underlying region, but rather moving the rect that was initially used to fill the region (no coupling with the area represented by the region). GUI hides this mechanic and instead calls a rect a region to confuse people.
  • empty.gif
    join.gif
    comment.gif
    -------- Setting up variable only for leak prevention, if a point is referenced in the event of this trigger --------
  • empty.gif
    join.gif
    set.gif
    Set Temp_location = (Target point of issued order)
  • empty.gif
    join.gif
    page.gif
    Custom script: call RemoveLocation(udg_Temp_location)
As far as I am aware this is not required as a leakable location object is only created when you explicitly create it. Simply having the event fire with a point target should not generate a location object and so should not leak.
  • empty.gif
    join.gif
    unit.gif
    Unit - Order (Triggering unit) to Move To (PG_Portal2Location offset by 200.00 towards PG_Portal2Angle degrees)
  • empty.gif
    join.gif
    comment.gif
    -------- This last action does not work at all for some reason. --------
  • empty.gif
    join.gif
    comment.gif
    -------- Even if teleportation works (with references to "location of unit" instead of "PG_PortalXLocation" variable), units get ordered behind the portal or to the other portal. --------
  • empty.gif
    joinbottom.gif
    comment.gif
    -------- The PG portal angle and portal location variables break the entire portal system for some unknown reason --------
As described at the top, this is because you destroyed the location referenced by PG_Portal2Location earlier and so it is now using the default value of a location at {0,0} (map origin) which is similar to using a null value.
 
Level 1
Joined
Feb 3, 2021
Messages
2
In PG New Portal you destroy the location referenced by udg_Temp_location while you still intend to use it in the future as a portal position. As such the other triggers that try to access it get an invalid, null like, location which represents the centre of the map.

Locations are complex objects that are referenced. A location value is a reference to a location object. Multiple location variables can reference the same location object. Assigning a location to a location variable assigns its reference, it does not make a copy of the location object and assign a new reference. If that location object is destroyed, then all variables referencing that location object now reference a destroyed location which will evaluate similar to a null location.

This is because you are not modifying the underlying region, but rather moving the rect that was initially used to fill the region (no coupling with the area represented by the region). GUI hides this mechanic and instead calls a rect a region to confuse people.

As far as I am aware this is not required as a leakable location object is only created when you explicitly create it. Simply having the event fire with a point target should not generate a location object and so should not leak.

As described at the top, this is because you destroyed the location referenced by PG_Portal2Location earlier and so it is now using the default value of a location at {0,0} (map origin) which is similar to using a null value.
Oh perfect! Many thanks to you.

I thought the point variable just records map coordinates. Thus after once creating a point, any variable that got its value from the original (later destroyed) point would retain their value like an integer or a real would.

If I now understood this correctly, the code should work (and I could get to tidying it up a bit) if I just remove any unnecessary calls to destroy temp_location? And the game should intelligently keep referencing this certain point instead of creating new ones all the time?

I'll get back to experimenting, but I could not have done this without your insight. Thanks again.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
If I now understood this correctly, the code should work (and I could get to tidying it up a bit) if I just remove any unnecessary calls to destroy temp_location? And the game should intelligently keep referencing this certain point instead of creating new ones all the time?
Yes. However you should destroy the old one when a new portal is made before you assign the variable to the new location. If you do not then that will be a location leak as all references to the old location object are lost and it is never removed.
 
Status
Not open for further replies.
Top