Will this work as intended?

Started by Flabort, July 30, 2014, 11:03:12 PM

Previous topic - Next topic

Flabort

This is unrelated to my previous thread regarding a script, and is for a different kind of unit.
I have here two codes. One is where you create a tower and attach this, fill out the details, and it will create a number of the other units, who maintain and run themselves.

The child units are there to circumvent the ops per frame limit.

The purpose is to create a "conveyor belt" of terrain that slowly moves upwards or downwards, taking creeper, digitalis, and units along with it. When the top or bottom of the belt is reached, respectively, the stuff at that edge is (hopefully) moved to the other edge.

$ChildScriptName:"CollumnarWarp.crpl"
$Top:0
$Bottom:0
$Left:0
$Right:0
$Direction:-1
$Delay:5
once
<-ChildScriptName ->ChildSN
<-Right <-Left do
"crplcore" I <-Top CreateUnit "Child" I concat ->!
"Child" I concat <-! <-ChildSN  AddScriptToUnit
"Child" I concat <-! <-ChildSN "Collumn" I SetScriptVar
"Child" I concat <-! <-ChildSN "Top" <-Top SetScriptVar
"Child" I concat <-! <-ChildSN "Bottom" <-Bottom SetScriptVar
"Child" I concat <-! <-ChildSN "Direction" <-Direction SetScriptVar
"Child" I concat <-! <-ChildSN "Delay" <-Delay SetScriptVar
loop
endonce
Self CONST_CREATEPZ FALSE SetUnitAttribute
Self 0 Destroy


#Scriptname:CollumnarWarp.crpl
$Collumn:0
$Top:0
$Bottom:0
$Direction:-1
$Delay:5
once
self CONST_COUNTSFORVICTORY FALSE SetUnitAttribure
self CONST_CREATEPZ FALSE SetUnitAttribute
self CONST_NULLIFIERDAMAGES FALSE SetUnitAttribute
self CONST_TAKEMAPSPACE FALSE SetUnitAttribute
endonce
<-Delay Delay
<-Bottom <-Top do
<-Collumn I GetCreeper "Creeper" I Concat ->!
<-Collumn I GetTerrain "Terrain" I Concat ->!
<-Collumn I GetDigitalisGrowth "Growth" I Concat ->!
<-Collumn I GetDigitalis "Digi" I Concat ->!
<-Collumn I GetUnitAt "Unit" I Concat ->!
loop
<-Bottom <-Direction add <-Top <-Direction add do
I <-Top lt if
<-Bottom ->Place
else
I <-Bottom gt if
<-Top ->Place
else
I ->Place
endif
endif
<-Collumn <-Place "Creeper" I <-Direction add Concat ->! SetCreeper
<-Collumn <-Place "Terrain" I <-Direction add Concat ->! SetTerrain
<-Collumn <-Place "Growth" I <-Direction add Concat ->! SetDigitalisGrowth
<-Collumn <-Place "Digi" I <-Direction add Concat ->! SetDigitalis
"Unit" <-Place concat <-! -1 eq not If
"Unit" <-Place concat <-! CONST_COORDY GetUnitAttribute ->Temp
"Unit" <-Place concat <-! CONST_COORDY <-Temp <-Direction add SetUnitAttribute
--Temp
endif
loop
My maps: Top scores: Sugarplum, Cryz Dal, Cryz Torri, Cryz Bohz (Click fetch scores, page courtesy of kwinse)

ParkourPenguin

Your first script is good for the most part, except for one little detail: you should add 1 to Right in the do loop, since that loop will terminate when Right = Left, not when Right < Left.
<-Right 1 add <-Left do


Your second script, however, needs a bit more work. First of all, there's a small typo on line 8. Change "SetUnitAttribure" to "SetUnitAttribute".

Secondly, you should do the same thing here that I suggested in your first script: add 1 to the upper boundary of the do loops.

Next, the spot at which you set all the stuff needs a bit of work:
<-Collumn <-Place "Creeper" I <-Direction add Concat ->! SetCreeper
<-Collumn <-Place "Terrain" I <-Direction add Concat ->! SetTerrain
<-Collumn <-Place "Growth" I <-Direction add Concat ->! SetDigitalisGrowth
<-Collumn <-Place "Digi" I <-Direction add Concat ->! SetDigitalis
"Unit" <-Place concat <-! -1 eq not If
"Unit" <-Place concat <-! CONST_COORDY GetUnitAttribute ->Temp
"Unit" <-Place concat <-! CONST_COORDY <-Temp <-Direction add SetUnitAttribute
--Temp
endif


Wouldn't the first four commands at the right be taking an item from an empty stack? All of those commands require 3 arguments: an x-coordinate, a y-coordinate, and some number. <-Collumn satisfies the x-coordinate, but the refwrite pops the <-Place and the concated string from the stack in all four occasions. I think you may have accidentally put refwrite instead of refread. Try changing all the ->! to <-! in those 4 lines.

Also, instead of adding Direction to I, it would be better to subtract it. You're trying to read the data you just saved in order to put it in the next spot, so you should undo what you did in the do parameters of the do loop- instead of adding Direction, subtract it.

And for the units, I don't quite know what you were doing. You can think of <-Place as the future y-coordinate of where you want to set everything. As such, it would make more sense to check if the unit that it just saved exists as opposed to whether or not there used to be a unit where you want to place the current unit you're concerned with. To do that, just get the UID using the same method as you did the other 4 things.

Since you can consider <-Place as the future y-coordinate of where you want to set everything, you don't actually need the variable Temp. Just change the y-coordinate of the same unit you're working with in the if statement to Place.

Here's the full second script with all the changes above made:
#Scriptname:CollumnarWarp.crpl
$Collumn:0
$Top:0
$Bottom:0
$Direction:-1
$Delay:5
once
self CONST_COUNTSFORVICTORY FALSE SetUnitAttribute
self CONST_CREATEPZ FALSE SetUnitAttribute
self CONST_NULLIFIERDAMAGES FALSE SetUnitAttribute
self CONST_TAKEMAPSPACE FALSE SetUnitAttribute
endonce
<-Delay Delay
<-Bottom 1 add <-Top do
<-Collumn I GetCreeper "Creeper" I Concat ->!
<-Collumn I GetTerrain "Terrain" I Concat ->!
<-Collumn I GetDigitalisGrowth "Growth" I Concat ->!
<-Collumn I GetDigitalis "Digi" I Concat ->!
<-Collumn I GetUnitAt "Unit" I Concat ->!
loop
<-Bottom <-Direction add 1 add <-Top <-Direction add do
I <-Top lt if
<-Bottom ->Place
else
I <-Bottom gt if
<-Top ->Place
else
I ->Place
endif
endif
<-Collumn <-Place "Creeper" I <-Direction sub Concat <-! SetCreeper
<-Collumn <-Place "Terrain" I <-Direction sub Concat <-! SetTerrain
<-Collumn <-Place "Growth" I <-Direction sub Concat <-! SetDigitalisGrowth
<-Collumn <-Place "Digi" I <-Direction sub Concat <-! SetDigitalis
"Unit" I <-Direction sub concat <-! -1 neq If
"Unit" I <-Direction sub concat <-! CONST_COORDY <-Place SetUnitAttribute
endif
loop


I hope all this makes sense after seeing what I meant. Anyways, if you have any other questions, don't hesitate to ask!  ;)
"Only a life lived for others is a life worthwhile."
-Albert Einstein

Flabort

#2
Typo fixed.
I'm not sure the "1 add" for the do is necessary, I guess that's something to check in testing.
Yeah, those were supposed to be refread.
I just barely understood what you meant by the sub instead of add.
Took me three rereads to understand the changes for unit movement. I didn't really remember what I was doing by the point I wrote that small section, so I'm glad you saw what I meant to do and fixed that. :)

You know what, I'll just grab your copy and replace mine with it, trying to wrap my head around the changes and change it myself won't work.

EDIT: IT WORKS! HAHAHAHAHAH! IT WORKS! Well, at least, it moves terrain properly. Haven't tested creeper, digi, or units yet. That's next!
My maps: Top scores: Sugarplum, Cryz Dal, Cryz Torri, Cryz Bohz (Click fetch scores, page courtesy of kwinse)

Flabort

Hmm... Well, it lags horribly. But that's to be expected. It could be worse.
However, I guess I'll only be using smaller warps than my test.
Second, it seems that regular emitters on the warp won't seed digitalis.

However, creeper and units on the warp zone move correctly and even warp around to the other side correctly.
Creeper still flows correctly on the warp zone, too.
After adding emmiters outside the warp with digitalis that is always attached to digi in the warp, it seems digi won't grow on the warp. Hypothesising that the speed of the warp is the cause and slowing it down to a delay of 16...
Still doesn't seed; growth still fails to happen.
Slowing the warp down to 25.
Digi still fails to form on or grow onto the warp.
I guess this may have to do with the current bugs with SetDigitalis?
My maps: Top scores: Sugarplum, Cryz Dal, Cryz Torri, Cryz Bohz (Click fetch scores, page courtesy of kwinse)

ParkourPenguin

I'm unaware of any bugs with SetDigitalis, but after a bit of testing, I think I know what's going on.

Digitalis has to wait for a specified period of time before it forms on the cell next to it. When you set the digitalis back every few frames, that "timer" resets back to 0 as well, effectively not allowing digitalis to spread at all onto that moving area. Or, at least, that's what I think is going on. If this is the case, then I can't think of any easy way of making digitalis grow on it. If you want me to, however, I can experiment with a few things that might simulate the growth of digitalis.

By the way, that lag is probably being caused by SetTerrain. Try making the area you're moving as flat as possible, and the lag should die down a bit.
"Only a life lived for others is a life worthwhile."
-Albert Einstein

Grayzzur

The lag is definitely being caused by SetTerrain. That's a horribly expensive call, as it causes the engine to redraw a bunch of textures. You don't even have to get around the CRPL op code limit to create massive lag with SetTerrain. That's why the wiki documentation for this command says:
Use this command sparingly and with caution - it has a severe impact on game performance.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Flabort

I expected it to lag, though.  :P
And it doesn't make Cryz Bohz unplayable, just... slow.

And as far as Digitalis, that's pretty much what I thought, too, which is why I experimented with slowing down the conveyer. Maybe I just didn't set the delay long enough when testing.
My maps: Top scores: Sugarplum, Cryz Dal, Cryz Torri, Cryz Bohz (Click fetch scores, page courtesy of kwinse)

stewbasic

There is a bug that growth created by SetDigitalisGrowth doesn't get spread to. I posted about it here:

http://knucklecracker.com/forums/index.php?topic=16362.0

I never got to the bottom of the issue (I got really inconsistent behaviour when I tested more in the same location, suggesting that some per-cell internal state was getting messed up) but there is a workaround in that thread.