Script only partially functional

Started by Atrex, May 03, 2014, 08:53:39 AM

Previous topic - Next topic

Atrex

I wrote a script that's supposed to make a CRPL tower move and create a ring of level 10 terrain around it, which it removes after passing the area. The intent was to get a creeper-covered asteroid drifting through space at the player. It seems to work fine, but only in the upper-right corner of the map.
# CreeperAsteroid.crpl
# Created on: 5/1/2014 7:03:26 PM
# ------------------------------------------

$targetX:30
$targetY:30
$moveSpeed:1
$size:7
$frequency:30
once
0 ->count
#Stores the initial terrain height at evey cell
MapWidth CreateListStartingSize ->xCoord
MapWidth 0 do
<-xCoord I MapHeight CreateListStartingSize SetListElement
loop
MapWidth 0 do
MapHeight 0 do
<-xCoord I GetListElement J I J GetTerrain SetListElement
loop
loop
<-targetX <-targetY <-moveSpeed QueueMove
while GetQueuedMoveCount 0 neq
repeat
CurrentX 2 <-size mul add CurrentX 2 <-size mul sub do
CurrentX 2 <-size mul add CurrentX 2 <-size mul sub do
I J CurrentCoords Distance <-size gt if
I ->CheckX J ->CheckY @GetOriginalTerrain <-terrainLevel I J GetTerrain neq if
I J <-terrainLevel SetTerrain
endif
else
I J GetTerrain 10 neq if
I J 10 SetTerrain
endif
endif
loop
loop
<-frequency Delay
endwhile
endonce
GetQueuedMoveCount

:GetOriginalTerrain
<-xCoord <-CheckX GetListElement <-CheckY GetListElement ->terrainLevel

stewbasic

To clarify, do you mean your disk of height 10 appears in the very upper right corner regardless of where the core is? Or it is centered at the core, but only if the core is in the upper right quadrant of the map?

Some other comments which hopefully help, but are maybe not related to the problem...

I believe J refers to the outer loop (at least according to the wiki page) so in L9 you probably want to use J for x. This won't matter if MapWidth = MapHeight.

In L15 you probably want to change CurrentX to CurrentY twice.

You might want to look for terrain cells to reset near the core's previous position rather than its current position - if the core moved a lot from one "repeat" to the next, the previous height 10 cells wouldn't be in the box that you iterate over. I guess the core probably isn't moving that fast though, and your box is twice as large as the disk.


Atrex

Thanks. Mixing up the I and J was the problem. Since the map I was using was very wide but not tall, it only found valid Y coordinates when it was near the corner.