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

Losing the point cast.

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2013
Messages
1,105
Hello, so here I am making a "toss" and a unit is taken from around the caster and thrown toward the target, although I haven't implemented a change in flying height just yet. ANYWAY--- My trigger Works fine as long as I don't Remove the TempPoints but as soon as I do remove them, it just goes to the center of playable...What am I doing wrong? I can only assume the temp location is not being saved properly but I'm failing to understand why.

Here's my trigs.

  • Toss Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Toss
    • Actions
      • Set Toss_MaxIndex = (Toss_MaxIndex + 1)
      • Set TempUnit = (Triggering unit)
      • Set Toss_TargetPoint[Toss_MaxIndex] = (Target point of ability being cast)
      • Set TempLoc = (Position of TempUnit)
      • Set TempLoc2 = Toss_TargetPoint[Toss_MaxIndex]
      • Set TempGroup = (Units within 300.00 of TempLoc matching ((((Matching unit) is A structure) Not equal to True) and (((Matching unit) belongs to an ally of (Triggering player)) Not equal to True)))
      • Set Thrown_Unit[Toss_MaxIndex] = (Random unit from TempGroup)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Storm Crow Form for (Random unit from TempGroup)) Less than 1
        • Then - Actions
          • Unit - Add Storm Crow Form to (Random unit from TempGroup)
        • Else - Actions
      • Trigger - Turn on Toss Loop <gen>
      • // Custom script: call RemoveLocation(udg_TempLoc)
      • // Custom script: call RemoveLocation(udg_TempLoc2)
  • Toss Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Toss_MaxIndex Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • For each (Integer Toss_CurrentIndex) from 1 to Toss_MaxIndex, do (Actions)
            • Loop - Actions
              • Set TempLoc = (Position of Thrown_Unit[Toss_CurrentIndex])
              • Set TempLoc2 = Toss_TargetPoint[Toss_CurrentIndex]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between TempLoc and TempLoc2) Less than or equal to Toss_ThresholdRange
                • Then - Actions
                  • Set Thrown_Unit[Toss_CurrentIndex] = Thrown_Unit[Toss_MaxIndex]
                  • Set Toss_TargetPoint[Toss_CurrentIndex] = Toss_TargetPoint[Toss_MaxIndex]
                  • Set Toss_CurrentIndex = (Toss_CurrentIndex - 1)
                  • Set Toss_MaxIndex = (Toss_MaxIndex - 1)
                • Else - Actions
                  • Set TempReal = (Angle from TempLoc to TempLoc2)
                  • Custom script: call SetUnitX(udg_Thrown_Unit[udg_Toss_CurrentIndex], GetUnitX(udg_Thrown_Unit[udg_Toss_CurrentIndex]) + udg_Toss_SpeedInterval * Cos(bj_DEGTORAD * udg_TempReal))
                  • Custom script: call SetUnitY(udg_Thrown_Unit[udg_Toss_CurrentIndex], GetUnitY(udg_Thrown_Unit[udg_Toss_CurrentIndex]) + udg_Toss_SpeedInterval * Sin(bj_DEGTORAD * udg_TempReal))
              • // Custom script: call RemoveLocation(udg_TempLoc)
              • // Custom script: call RemoveLocation(udg_TempLoc2)
 
When you set TempLoc2 to Toss_TargetPoint[Toss_MaxIndex] it is not creating a new location. It is actually just using the same location.

So when you remove it, that means both TempLoc2 and Toss_TargetPoint are now pointing to a removed location (causing the things to appear in the center of the map). The fix is to only destroy the point once you finish the spell. It is okay to remove "TempLoc" because you are making a new location each time "Position of Thrown_Unit[]", but TempLoc2 is pointing to Toss_TargetPoint, which is a fixed location the entire time. You would just add:
  • Custom script: call RemoveLocation(udg_TempLoc2)
Probably in the "Then" actions for when the distance is less than or equal to the threshold range.

EDIT: For a visual on how pointers and leaks work, see this:
http://oi50.tinypic.com/dg0115.jpg
It is an old image I made a long time ago, lol. Thanks to Spartpilo for keeping it in his siggy. :)

Basically, in that image I'm reassigning TempLoc to new locations. Those locations are kept in memory. Just because I set TempLoc to a different location doesn't mean the old ones are cleared. Once I remove "TempLoc", it will only remove what it is currently pointing to. The other two are no longer pointed to, so they just stay there.
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
So I'm changing the 1st trigger to not remove TempLoc2 when its cast, and then I'm not removing TempLoc2 in the 2nd trigger until it meets the threshold? This does allow the spell to work and not default to the middle--But aren't I not leaking a LOT now?
 
Status
Not open for further replies.
Top