CRPL related questions

Started by eduran, October 13, 2013, 09:10:10 AM

Previous topic - Next topic

Cotters

Quote from: Michionlion on October 17, 2013, 09:49:23 PM



Arguments Notation
Effect_Num,X,Y,Z,ScaleX,ScaleY,Speedn1 x1 y1 z1 f1 f2 f3 -

Those 'Arguments' - they list what you pass into the method.  the very first arg - 'Effect_Num' - is what you need to change.  In the examples case, it is the number '14'.
Aha! thanks so much!  :)
I mistook the 14 as the pixel ratio.

Lost in Nowhere

Why isn't this working?
# CreeperCannon.crpl
# Created on: 10/9/2013 8:02:23 AM
# ------------------------------------------

$RADIUS:7
$POWER:1.2 #Larger=weaker
$EXTRACREEPER:1
$CHARGETIME:7200
$RELOADTIME:1800

once
1 SetPopupTextAlwaysVisible
<-CHARGETIME 0 do
1 Delay
I asfloat <-CHARGETIME asfloat div 100 asfloat mul floor "%" Concat SetPopupText
loop
endonce

GetTimer0 0 lte if
<-RELOADTIME SetTimer0
#create bullet here
@GetClosestUnit ->closestUnit
"crplcore" CurrentCoords CreateUnit ->NewUnit
<-NewUnit "MegaBullet.crpl" AddScriptToUnit
<-NewUnit "MegaBullet.crpl" "TARGETX" <-closestUnit CONST_COORDX GetUnitAttribute SetScriptVar
<-NewUnit "MegaBullet.crpl" "TARGETY" <-closestUnit CONST_COORDY GetUnitAttribute SetScriptVar
<-NewUnit "MegaBullet.crpl" "RADIUS" <-RADIUS SetScriptVar
<-NewUnit "MegaBullet.crpl" "POWER" <-POWER SetScriptVar
<-NewUnit "MegaBullet.crpl" "EXTRACREEPER" <-EXTRACREEPER SetScriptVar
<-NewUnit "CONST_COUNTSFORVICTORY" 0 SetUnitAttribute
<-NewUnit "CONST_NULLIFIERDAMAGES" 0 SetUnitAttribute
<-NewUnit "CONST_CREATEPZ" 0 SetUnitAttribute
<-NewUnit "CONST_DESTROYMODE" 1 SetUnitAttribute
<-NewUnit "CONST_SUPPORTSDIGITALIS" 0 SetUnitAttribute
<-NewUnit "CONST_TAKEMAPSPACE" 0 SetUnitAttribute
<-NewUnit "main" "Custom1" SetImage
endif
<-RELOADTIME GetTimer0 sub <-RELOADTIME div 100 mul floor "%" Concat SetPopupText

:GetClosestUnit
99999999 ->closestDistance
0 ->closestUnit
CurrentCoords 1000 GetUnitsInRange ->unitCount
<-unitCount neq0 if
<-unitCount 0 do
->unit
CurrentCoords <-unit CONST_COORDX GetUnitAttribute <-unit CONST_COORDY GetUnitAttribute Distance ->d
<-d <-closestDistance lt if
<-d ->closestDistance
<-unit ->closestUnit
endif
loop
endif
<-closestUnit

:destroyed
CurrentCoords 1000 AddCreeper

The tower just sits there, displaying "0%."
It's supposed to wait for CHARGETIME and then wait for RELOADTIME between firing bullets, with the text displaying how close it is to building/firing.
Don't die! :)

eduran

Quote from: Lost in Nowhere on October 17, 2013, 11:06:39 PM
It's supposed to wait for CHARGETIME and then wait for RELOADTIME between firing bullets, with the text displaying how close it is to building/firing.
I think you need an asfloat in your second SetPopupText.
Another question:
I am trying to make a custom emitter that looks exactly like a normal emitter. How do I get SetPopupText to display two lines?

ThirdParty

Quote from: eduran on October 19, 2013, 11:44:01 AMHow do I get SetPopupText to display two lines?
As far as I know there are no escape codes; you have to type the return directly into your script.  e.g.:

SetPopupTextAlwaysVisible(True)
SetPopupText("Line 1
Line 2")

Lost in Nowhere

This isn't working:
# LifeEngine.crpl
# Created on: 10/30/2013 7:23:43 PM
# ------------------------------------------

$Width:37
$Height:36
$CellAmt:2
$Period:15

once
1 ->state
@awake
endonce

<-state if
#Gets creeper state

CurrentCoords ->y ->x
<-Height <-y add <-y do
<-Width <-x add <-x do
I J GetCreeper 0 gt "x" I concat "y" J concat concat ->!
loop
loop

1 Delay
endif
<-state not if
#Recalculates creeper
CurrentCoords ->y ->x

<-Height <-y add <-y do
<-Width <-x add <-x do
I J @GetSurroundingNum ->n

"x" I concat "y" J concat concat <-! if #if the cell is "alive"
<-n 2 eq <-n 3 eq or if #if it has 2 or 3 neighbors
I J <-CellAmt SetCreeper
else #otherwise
I J 0 SetCreeper
endif
else #if the cell is "dead"
<-n 3 eq if #if it has 3 neighbors
I J <-CellAmt SetCreeper
endif
endif
loop
loop

<-Period 1 sub Delay
endif

<-state not ->state

:awake
CurrentCoords ->y ->x
<-Height 0 do
<-Width 0 do
<-x I add <-y J add TRUE FALSE SetPinFieldCell
loop
loop

:GetSurroundingNum
->y2 ->x2
0 ->t
<-y2 1 add <-y2 1 sub do
<-x2 1 add <-x2 1 sub do
<-t "x" I concat "y" J concat concat <-! add ->t
loop
loop
<-t "x" <-x2 concat "y" <-y2 concat concat <-! sub ->t

It is supposed to simulate Conway's Game of Life using creeper in the area specified, but it just erases all creeper.
(In the case that you don't know what that is: http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
Don't die! :)

ThirdParty

Quote from: Lost in Nowhere on October 30, 2013, 10:43:23 PMThis isn't working:

I find your reverse polish syntax really hard to read, but I think the "->t" at the end of :GetSurroundingNum was maybe meant to be a "return".

Grayzzur

Another thing to consider is your do loops.

3 0 do
  # runs for 0, 1 and 2. Does not run for 3
loop

I think you may be trying to work on a 3x3 grid around a starting point. If that's the case, you may want to try:
   <-y2 2 add <-y2 1 sub do
      <-x2 2 add <-x2 1 sub do
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Lost in Nowhere

#22
ThirdParty: No, that last line is meant to just make it not count the cell in question. I completely forgot the return.
Grayzzur: I just thought about that while I was laying in bed, half-asleep.
And yay, it works now!
Don't die! :)

knucracker

Note that you can set walls (and unset them) with great efficiency as well.  So if you are using Creeper because it is fast to set (in your game of life sim), also consider walls since they are equally fast.  You could also create a 'GUI' the player could click on or for display purposes at the top or bottom of the map that would allow you to clear the grid, create well known structures (gliders, etc.), or allow you to click to paint or erase.  See the Credits mission for some code on how to create GUI.

Lost in Nowhere

#24
I'm mostly using it because it is very easy to kill, though using walls could also work.
I made a script that creates a glider, which worked. I also tried a glider gun, but it dies shortly after emitting a glider... which it destroys.
Also, somewhere else you mentioned that there is a limit of 500,000 or so operations per tower per frame. What exactly constitutes a operation in this context?
Don't die! :)

J

Quote from: Lost in Nowhere on October 31, 2013, 05:28:43 PM
Also, somewhere else you mentioned that there is a limit of 500,000 or so operations per tower per frame. What exactly constitutes a operation in this context?
Every opcode is counted. so1 2 addcounts as 3 operations/opcodes

Grauniad

Quote from: J on October 31, 2013, 05:35:00 PM
Quote from: Lost in Nowhere on October 31, 2013, 05:28:43 PM
Also, somewhere else you mentioned that there is a limit of 500,000 or so operations per tower per frame. What exactly constitutes a operation in this context?
Every opcode is counted. so1 2 addcounts as 3 operations/opcodes

J: Actually I believe that is one opcode with two operands. :)
A goodnight to all and to all a good night - Goodnight Moon

MagmaMcFry

No, those are three opcodes, there is no such thing as operands in the syntax of a simple stack-based language. The first opcode pushes a 1 to the stack, the second opcode pushes a 2 to the stack, and the third opcode pops two values and pushes their sum. This leads to something that looks like reverse polish notation, but is actually caused by something else. /tmyk

Grauniad

My bad, I conflated CRPL with assembler. You are right.
A goodnight to all and to all a good night - Goodnight Moon

Lost in Nowhere

Why does CRPL seem to not like me?
Anyways:
This is supposed to fire exploding globs of creeper that function similar to the Mass orbital weapons, but create more creeper.
# GremlinTower.crpl
# Created on: 11/7/2013 3:39:55 PM
# ------------------------------------------

$Build:1800
$Wait:1800
$Amt:50.0 #Amount of creeper is divided by this
$Height:0.5

once
FALSE ->Built
CurrentX ->x
CurrentY ->y
Self "CONST_MAXAMMO" <-Build SetUnitAttribute
Self "CONST_SHOWAMMOBAR" TRUE SetUnitAttribute
endonce

<-Built if
Self "CONST_AMMO" GetUnitAttribute ->a
<-a Self "CONST_MAXAMMO" GetUnitAttribute gte if
#fire a bullet
"CRPLCORE" CurrentCoords CreateUnit ->u
@GetClosestUnit ->v
<-u "CRBullet.crpl" AddScriptToUnit
<-u "GremlinBullet.crpl" "TX" <-v "CONST_XCOORD" GetUnitAttribute SetScriptVar
<-u "GremlinBullet.crpl" "TY" <-v "CONST_YCOORD" GetUnitAttribute SetScriptVar
0 ->p
CurrentY 2 add CurrentY 1 sub do
CurrentX 2 add CurrentX 1 sub do
I J GetCreeper <-p add ->p
I J 0 SetCreeper
loop
loop
<-u "GremlinBullet.crpl" "Power" <-p SetScriptVar
<-u "GremlinBullet.crpl" "Height" <-Height SetScriptVar
Self "CONST_AMMO" 0 SetUnitAttribute
else
Self "CONST_AMMO" <-a 1 add SetUnitAttribute
endif
else
Self "CONST_AMMO" GetUnitAttribute ->a
<-a Self "CONST_MAXAMMO" GetUnitAttribute gte if
Self "CONST_MAXAMMO" <-Wait SetUnitAttribute
Self "CONST_AMMO" 0 SetUnitAttribute
TRUE ->Built
else
Self "CONST_AMMO" <-a 1 add SetUnitAttribute
endif
endif

<-x <-y SetCurrentCoords

:GetClosestUnit
99999999 ->closestDistance
0 ->closestUnit
CurrentCoords 9999 GetUnitsInRange ->unitCount
<-unitCount neq0 if
<-unitCount 0 do
->unit
CurrentCoords <-unit CONST_COORDX GetUnitAttribute <-unit CONST_COORDY GetUnitAttribute Distance ->d
<-d <-closestDistance lt if
<-d ->closestDistance
<-unit ->closestUnit
endif
loop
endif
<-closestUnit

# GremlinBullet.crpl
# Created on: 11/7/2013 3:42:35 PM
# ------------------------------------------

$Power:100
$TX:0
$TY:0
$Height:0.5

once
<-TX <-TY 8 QueueMove
Self "main" "Custom0" SetImage
Self "CONST_NULLIFIERDAMAGES" FALSE SetUnitAttribute
Self "CONST_SUPPORTSDIGITALIS" FALSE SetUnitAttribute
Self "CONST_COUNTSFORVITORY" FALSE SetUnitAttribute
Self "CONST_SUPPORTSDIGIALIS" FALSE SetUnitAttribute
Self "CONST_TAKESMAPSPACE" FALSE SetUnitAttribute
endonce

GetQueuedMoveCount eq0 if
.75 <-Power mul PI div 1 3 div pow ->Radius
CurrentCoords GetTerrain ->t
<-Radius 1 add <-Radius neg do
<-Radius 1 add <-Radius neg do
I 2 pow J 2 pow add ->a
<-a <-Radius lte if
<-a sqrt <-Height mul ->b
I J <-b 2 mul AddCreeper
I J GetTerrain ->n <-t <-b sub min 1 max ->c
I J <-c SetTerrain
endif
loop
loop

CurrentCoords <-Radius GetUnitsInRange ->unitCount
<-unitCount neq0 if
<-unitCount 0 do
2 Destroy
loop
endif
Self 2 Destroy
endif
Don't die! :)