Author Topic: Making a emitter at Powerzones  (Read 95 times)

piggood

  • Jr. Member
  • **
  • Posts: 16
Making a emitter at Powerzones
« on: June 09, 2019, 05:21:34 am »
I don't Know What's Wrong But It only Destroys half of powerzones and doesn't create Any CRPL cores.
Code: [Select]
once
Self "Main" 2 2 SetImageScale
endonce

CurrentCoords 300 SetCreeper
30 Delay

:Destroyed
0 0 9999 TRUE GetAllUnitsInRange 0 do
->unit

<-unit GetUnitType "POWERZONE" eq if
<-unit GetUnitAt ->x ->y
Destroy(<-unit 0)
"CRPLCore" <-x <-y CreateUnit ->child
<-child "Just.crpl" AddScriptToUnit
endif
loop

Builder17

  • Community Guild
  • *****
  • Posts: 993
  • My account picture is from Nitrome Mutiny.
Re: Making a emitter at Powerzones
« Reply #1 on: June 09, 2019, 06:21:13 am »
Edit: Read message from Grabz for answer.
« Last Edit: June 09, 2019, 09:25:43 am by Builder17 »

Grabz

  • Community Guild
  • *****
  • Posts: 146
  • Where will you be when the creeper waves hit?
Re: Making a emitter at Powerzones
« Reply #2 on: June 09, 2019, 06:31:00 am »
The issue with your script lies here:
Code: [Select]
<-unit GetUnitAt ->x ->yAs per the wiki page for GetUnitAt, this is a function that takes two arguments: x and y, and returns the unit ID if a unit was found at said coordinates. In your script this is backwards, presumably because of a false assumption that this function would give the coordinates of the unit. This is the reason only half of power zones are destroyed - the function returns one argument but you are saving two, so you are saving what the function returns into `x`, and then saving a power zone UID from GetAllUnitsInRange into `y`, thus half of all the power zone UID's are lost from the stack.

Replace this line:
Code: [Select]
<-unit GetUnitAt ->x ->yWith this:
Code: [Select]
<-unit CONST_COORDX GetUnitAttribute ->x
<-unit CONST_COORDY GetUnitAttribute ->y
And your script should work fine. Reference: GetUnitAttribute

piggood

  • Jr. Member
  • **
  • Posts: 16
Re: Making a emitter at Powerzones
« Reply #3 on: June 09, 2019, 07:54:39 am »
Thanks!  :D

Grabz

  • Community Guild
  • *****
  • Posts: 146
  • Where will you be when the creeper waves hit?
Re: Making a emitter at Powerzones
« Reply #4 on: June 10, 2019, 04:20:55 am »
As a side note, functions that return coordinates, for example:
Code: [Select]
CurrentCoords ->y ->xalways put x first on the stack, and then y, therefore to save them into variables, you first have to save y (as it was inserted last, it's the last item on the stack) then x.

This is largely arbitrary, you could have your own CRPL function that puts coordinates on the stack in the order y x, and then you would retrieve them by doing ->x ->y. None of built in CRPL functions use this order however so it is best to follow the standard.