Using Lists To Move Creeper

Started by Pscioed, July 04, 2014, 01:44:34 PM

Previous topic - Next topic

Pscioed

I have made a script that should move creeper down the map, looping from the top to the bottom. Unfortunately, I have done something wrong and cannot for the life of me figure out what is going on. I have traced various things and tried lots of methods to try to debug, but haven't gotten anywhere. There are 2 lists that should alternate saving and loading rows of creeper as the loop moves down the map, but the behavior is not what I expected. Can anyone help show me what I am doing wrong?


once
0 SetCreeperFlowRate
CreateList ->CreeperRow0
CreateList ->CreeperRow1
10 0 do
<-CreeperRow0 i 0 SetListElement
<-CreeperRow1 i 0 SetListElement
10 0 do
i j 1 SetTerrain
i j 0 SetCreeper
loop
loop
30 SetTimer0
5 5 1 SetCreeper
7 6 1 SetCreeper
endonce

GetTimer0 eq0 if
9 1 do
9 1 do
i 2 mod if
<-CreeperRow0 j GetCreeper(j add(i 1)) SetListElement
j i GetListElement(<-CreeperRow1 j) SetCreeper
else
<-CreeperRow1 j GetCreeper(j add(i 1)) SetListElement
j i GetListElement(<-CreeperRow0 j) SetCreeper
endif
loop
loop
30 SetTimer0
endif

ParkourPenguin

I think I see what you did here.
Let's say that, hypothetically, somewhere in the middle of the loop, the two lines of code between if and else will run.
<-CreeperRow0 j GetCreeper(j add(i 1)) SetListElement
What you're doing here is copying the creeper data in the next row into CreeperRow0. When the inner loop runs again, the stuff in the else block will run:
j i GetListElement(<-CreeperRow0 j) SetCreeper
What this does is it will set the creeper in the now-current row (was previously that "next row" that the data was copied into) using the data found in CreeperRow0.

So, to make it as simple as possible, you're saving the creeper found in one location into a list and setting it right back in the exact same place.

Therefore, when you set the creeper, try setting it in the next row instead of the current row. It's completely safe to do so since you already "saved" the creeper that was there in the other list. Like so:
i 2 mod if
<-CreeperRow0 j GetCreeper(j add(i 1)) SetListElement
j add(i 1) GetListElement(<-CreeperRow1 j) SetCreeper
else
<-CreeperRow1 j GetCreeper(j add(i 1)) SetListElement
j add(i 1) GetListElement(<-CreeperRow0 j) SetCreeper
endif


Please let me know if this works out for you. If it doesn't or if you want help with something else, don't hesitate to ask! :)
"Only a life lived for others is a life worthwhile."
-Albert Einstein

Pscioed

Thanks a bunch, the code you gave me worked great. It comes to mind that every time the variable "i" is used it always has 1 added to it. The final working code is now:

i 2 mod if
<-CreeperRow0 j GetCreeper(j i) SetListElement
j i GetListElement(<-CreeperRow1 j) SetCreeper
else
<-CreeperRow1 j GetCreeper(j i) SetListElement
j i GetListElement(<-CreeperRow0 j) SetCreeper
endif


Now I am off to do something useful with this... Thanks again for the help :)

ZackNAttack

Zack on cw3