Leak with point arrays

Status
Not open for further replies.
Level 14
Joined
Aug 30, 2004
Messages
909
Oddly I'm getting a bug. It may not be possible for you guys to help without a ton of other triggers that I don't want to subject you to. I'm still new to leaks, so perhaps you could just answer this question:

If I do a custom script: call RemoveLocation and remove a variable just BEFORE I assign it, is there any problem with that? I would assume that would remove the old point, and store the new one. That doesn't seem to happen in my trigger below. Roughly what happens is this, there's an array of integers from 1 to 75 that stores integers that correspond to the custom values of different units. I use the following variable arrays to correpond to those custom values.

The boolean variable AiBoolean[1-75] stores a boolean that determines if I use AI to move the unit.

The point variable MovePoint[1-75] determines where on the map the unit is going.

The unit variable AiTarget[1-75] stores the enemy of the current unit.

The point variable defaultMove[1-75] stores where the target should move to if he isn't fighting anyone.

So for the unit with custom value 1, AiBoolean[1] tells me if the computer controls him or not, MovePoint[1] tells me where to move him, AiTarget[1] tells me who he's trying to kill, and if that guy dies defaultMove[1] tells me where to send him next.

The following trigger goes through all the computer units every .5 seconds and assigns their appropriate move points.

For each (Integer a2) from 1 to 75, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
AiBoolean[a2] Equal to True
//Only computer controlled units (AiBoolean = yes) get updated
Then - Actions
//Here I want to remove their previous order to avoid a leak. ***this is what breaks it***
Custom script: call RemoveLocation (udg_MovePoint[udg_a2])
//Below I assign their new move point to be their target, so they move toward their enemy
Set MovePoint[a2] = (Position of AiTargets[a2])
Set turn[a2] = True
Else - Actions
Do nothing
-------- if you have no target, and are AI; go to default position and overwrite the center of map, which it was assigned above --------
//If AiTargets is dead or non-existent, its position is the middle of the map; so I just assigned a lot of units to go to the middle if they have no target. This trigger corrects that.
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
AiBoolean[a2] Equal to True
Or - Any (Conditions) are true
Conditions
(AiTargets[a2] is alive) Equal to False
AiTargets[a2] Equal to No unit
Then - Actions
//If their target is dead or non-existent, I assign their new MovePoint to be their default
Custom script: call RemoveLocation (udg_MovePoint[udg_a2])
Set MovePoint[a2] = defaultMove[a2]
Set turn[a2] = True
Else - Actions
Do nothing


Here's what happens. When I delete the first Custom Script removeLocation action, the trigger works fine. Units chase their enemies; when their enemies die they move to their default move location. So the second Custom Script doesn't seem to break anything.

But when I leave in the first Custom Script which I marked above with ***this is what breaks it****, units move to the center of the map and try to kill it. In other words, their MovePoint variable is still set to the center of the map, not to their defaultMove.

I understand I'm not posting the other massive triggers I have, but all I'm doing is deleting a point that I'm about to overwrite anyway! If I understand leaks, deleting a point with a Custom Script one line before I assign that point a new variable shouldn't make any changes at all; and yet it is.

Thanks, sorry for being so long.

Darwin
 
Last edited:
Level 14
Joined
Aug 30, 2004
Messages
909
a2? wtf? is this GUI? AFAIK, arrays must only use integers.

Stop using acronyms!

I have loop that uses Integer A; I wanted a second loop so I make an integer called a2.

If GUI means Global User Interface or something that means I'm just using the thing Blizzard gave us, then yes.

I don't know what AFAIK means.

I believe Damage has fixed my problem though.
 
Level 8
Joined
Jun 26, 2010
Messages
530
Stop using acronyms!

I knew crap about acronyms at first, but when i realized we could see what one acronym means in less than 10 seconds by typing it on google, i started using ;p
Also, AFAIK means As Far As I Know.

I have loop that uses Integer A; I wanted a second loop so I make an integer called a2.

Using loops inside loops is probably not a good thing. Also, you should use Integer B for the loop inside the Integer A. I don't even know where you found integer a2.

If GUI means Global User Interface or something that means I'm just using the thing Blizzard gave us, then yes.

GUI means Graphic User Interface.
 
Level 15
Joined
Aug 31, 2009
Messages
776
To make things easier for us to follow, could you right click the trigger icon at the top of the trigger's code and select "copy as text" then place a
  • tag around it in the post?
  • You can also leave out the more complex parts of the trigger (just delete as necessary) but it will make it a fair bit easier to read through.
 
Level 14
Joined
Aug 30, 2004
Messages
909
  • AI and Missile Track AI Fire
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • -------- --- --------
      • -------- Order missiles and AI units --------
      • -------- --- --------
      • For each (Integer a2) from 1 to 75, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AiBoolean[a2] Equal to True
              • (AiTargets[a2] is alive) Equal to True
            • Then - Actions
              • Custom script: call RemoveLocation (udg_MovePoint[udg_a2])
              • Set MovePoint[a2] = (Position of AiTargets[a2])
              • Set turn[a2] = True
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AiBoolean[a2] Equal to True
              • Or - Any (Conditions) are true
                • Conditions
                  • (AiTargets[a2] is alive) Equal to False
                  • AiTargets[a2] Equal to No unit
            • Then - Actions
              • Custom script: call RemoveLocation (udg_MovePoint[udg_a2])
              • Set MovePoint[a2] = defaultMove[a2]
              • Set turn[a2] = True
            • Else - Actions
              • Do nothing
Thanks, I actually didn't know how people posted like that.
 
Level 15
Joined
Aug 31, 2009
Messages
776
From what I can see, there's nothing particularly wrong with this method. You're correctly removing an old point and then defining a new one. What you're saying is, when you remove the first custom script it causes the units to not respond correctly. Could you show me the exact piece of the trigger that orders the units to move? It could be due to its simultaneous running with this trigger that it is ordering before the point is re-assigned.

This can occur if you use "For Each Loop for Integer A" in two separate triggers that run at the same time.

One other small note, there's no need to a "Do Nothing" at the end strands of a If/Then/Else. It literally does nothing... but oddly enough, it still executes code (i.e. code telling the computer to do nothing, lol) and hence takes up processing time - though little, it's still nice to not use it up, aye?
 
Status
Not open for further replies.
Top