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

[Spell] Question About De-indexing Points

Status
Not open for further replies.
Level 8
Joined
Nov 9, 2011
Messages
326
so i was working on a spell but now when the spell ends i need to de-index the target point.

Now i know how to do that i am just wondering about the third line here. do i need it ?
  • Untitled Trigger 004
    • Events
    • Conditions
    • Actions
      • Custom script: call RemoveLocation(udg_Blizzard_Point[udg_Blizzard_tempInt])
      • Set Blizzard_Point[Blizzard_tempInt] = Blizzard_Point[Blizzard_Index]
      • Custom script: call RemoveLocation(udg_Blizzard_Point[udg_Blizzard_Index])
      • Set Blizzard_Index = (Blizzard_Index - 1)
Now if i dont do the third line of code here that means that the last indexed point will remain and may cause leaks?
Can anyone help?

EDIT: edited the first line of code to include ''blizzard'' in tempint part
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Actually you must not use it. Set Blizzard_Point[Blizzard_tempInt] = Blizzard_Point[Blizzard_Index] causes that both varaibles to point to Blizzard_Point[Blizzard_Index]. Removing Blizzard_Point[Blizzard_Index] will also remove Blizzard_Point[Blizzard_tempInt]. The used point has already been removed with call RemoveLocation(udg_Blizzard_Point[udg_tempInt]).
 
Level 8
Joined
Nov 9, 2011
Messages
326
i dont think u got what i meant.
ok example
Point 1 - index 1
Point 2 - index 2
Point 3 - index 3
Now Index 1 Finishes
So u swap it with the last index to take its place
first remove the point call RemoveLocation(udg_Point[udg_tempInt] < so its removed and no longer exists
So ended spell> Point[tempInt] > to Point[Index] < last index (3)
EDIT: u also Index -1 so the point still stays

Now the Last indexed Location still exists. Sure it can be overwritten when another instance of the spell is cast but is this bad? to just leave a point like that.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Keep in mind that point variables are only pointers, that point to a certain part in the memory. Using RemoveLocation() you remove this part in the memory. If two point variables point to the same part, you only need to remove it once.
Example:

Spell 1: Point[1]=Location1
Spell 2: Point[2]=Location2
Spell 3: Point[3]=Location3

Blizzard_Index = 3

Spell 1 finishes:

Remove Location Blizzard_Point[udg_Blizzard_tempInt]:
> Removes the Location, which Blizzard_Point[udg_Blizzard_tempInt] references
> (Location1)
> Blizzard_Point[1]=RemovedLocation

Blizzard_Point[Blizzard_tempInt] = Blizzard_Point[Blizzard_Index]
> Blizzard_Point[1]=Location3

Blizzard_Index = (Blizzard_Index - 1)


After that:

Spell 1: Point[1]=Location3
Spell 2: Point[2]=Location2
Spell 3: Point[3]=Location3

Blizzard_Index = 2

Spell 1 finishes:

Remove Location Blizzard_Point[udg_Blizzard_tempInt]:
> Removes the Location, which Blizzard_Point[udg_Blizzard_tempInt] references
> (Location1)
> Blizzard_Point[1]=RemovedLocation

Blizzard_Point[Blizzard_tempInt] = Blizzard_Point[Blizzard_Index]
> Blizzard_Point[1]=Location3

RemoveLocation(udg_Blizzard_Point[udg_Blizzard_Index])
> Removes the Location, which Blizzard_Point[udg_Blizzard_Index] references
> (Location3)
> Blizzard_Point[1]=RemovedLocation
> Blizzard_Point[3]=RemovedLocation

Blizzard_Index = (Blizzard_Index - 1)

After that:

Spell 1: Point[1]=RemovedLocation
Spell 2: Point[2]=Location2
Spell 3: Point[3]=RemovedLocation

Blizzard_Index = 2
 
Status
Not open for further replies.
Top