(solved) Having some issues with GetUnitType, can anyone help?

Started by Clean0nion, December 06, 2013, 09:12:37 PM

Previous topic - Next topic

Clean0nion

Hello!
I have here a script, and it is pasted in this spoiler.
Spoiler
# net_terp_edit.crpl
# Created on: 12/5/2013 7:18:30 PM
# ------------------------------------------

#SCRIPTS WE HAVE FROM THE TERP
#TO BE ADDED image "laser"
#terrain level to set the land to
#radius - the search radius for the terp
#bounty - the unit we're looking for (not used)
#1delay - delay between each tower that we terp
#delay - delay between each cell that we terp

once 0 ->edit endonce

<-edit 1 eq if

   CurrentCoords <-radius GetUnitsInRange 0 do
      GetUnitType "PULSECANNON" eq if
         ->targetUID
#      endif
#   loop

<-targetUID CONST_COORDX GetUnitAttribute ->tx
<-targetUID CONST_COORDY GetUnitAttribute ->ty

<-1delay Delay

<-tx 2 sub ->ex
<-ty 2 sub ->ey
@Terraform

<-tx 1 sub ->ex
<-ty 2 sub ->ey
@Terraform

<-tx ->ex
<-ty 2 sub ->ey
@Terraform

<-tx 1 add ->ex
<-ty 2 sub ->ey
@Terraform

<-tx 2 add ->ex
<-ty 2 sub ->ey
@Terraform

<-tx 2 add ->ex
<-ty 1 sub ->ey
@Terraform

<-tx 2 add ->ex
<-ty ->ey
@Terraform

<-tx 2 add ->ex
<-ty 1 add ->ey
@Terraform

<-tx 2 add ->ex
<-ty 2 add ->ey
@Terraform

<-tx 1 add ->ex
<-ty 2 add ->ey
@Terraform

<-tx ->ex
<-ty 2 add ->ey
@Terraform

<-tx 1 sub ->ex
<-ty 2 add ->ey
@Terraform

<-tx 2 sub ->ex
<-ty 2 add ->ey
@Terraform

<-tx 2 sub ->ex
<-ty 1 add ->ey
@Terraform

<-tx 2 sub ->ex
<-ty ->ey
@Terraform

<-tx 2 sub ->ex
<-ty 1 sub ->ey
@Terraform

      endif
   loop

endif

:Terraform
   <-addition if
      <-ex <-ey dup2 GetTerrain <-addition add SetTerrain
   else
      <-ex <-ey <-terrain SetTerrain
   endif
   <-delay Delay
[close]
What it's supposed to do is look inside a small radius (in this case the radius is 10) for a pulse cannon. When it finds one, it surrounds it level "terrain" terrain. In this cases "terrain" is 10.
This should work flawlessly. Instead, when there is a pulse cannon on its range, it builds a wall around a different unit in its range. So it waits for a pulse cannon, then changes the terrain around a different unit.
And when it does this, it only does it once per save.

Can anyone help? I'm assuming something's gone completely wrong with how I've been extracting the UID.

Grayzzur

GetUnitsInRange puts a list of units in range on the stack.

GetUnitType takes a unit id off the stack and returns the unit type. It's consuming the unit id, so when you find one, you're storing the NEXT unit id in targetUID there. You need to save the unit id in case you need it.

 CurrentCoords <-radius GetUnitsInRange 0 do
   ->uID
   <-uID GetUnitType "PULSECANNON" eq if
     <-uID ->targetUID
     # Do stuff with targetUID
   endif
 loop
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Clean0nion

Quote from: Grayzzur on December 06, 2013, 09:23:33 PM
GetUnitsInRange puts a list of units in range on the stack.

GetUnitType takes a unit id off the stack and returns the unit type. It's consuming the unit id, so when you find one, you're storing the NEXT unit id in targetUID there. You need to save the unit id in case you need it.

 CurrentCoords <-radius GetUnitsInRange 0 do
   ->uID
   <-uID GetUnitType "PULSECANNON" eq if
     <-uID ->targetUID
     # Do stuff with targetUID
   endif
 loop

Riiight. Thanks! I'll test this now.