CRPL related questions

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

Previous topic - Next topic

eduran

Edit: Since I don't want to flood the forum with new threads for every question about CRPL that I can't answer myself I renamed this thread. Feel free to add your own questions to mine.


As soon as I try anything higher than a value of 1.3 for SetCreeperFlowRate the creeper is all over the map and randomly turning into anti-creeper. The same happens with SetCreeperFlowRateOnDigitalis. Is that a bug or am I doing something wrong?
This is the script I was using:
once
2 SetCreeperFlowRate
endonce


J

#1
Use values from 0 to 1, if it is 1 the creeper will be divided equally over the cell with creeper and the 4 cells next to it. If it is higher than 1.3, it will move more creeper than present and thus, it will create AC. You might be able to prevent this by emitting creeper in a 2x2 region.

eduran

Thank you, that clears things up.

In the meantime I managed to hit another problem, so I am going to repurpose this thread to ask any questions I come up with.
Here goes:
Trace(div(4 2)) #displays '2' in trace log
Trace(div(2 4)) #displays '0'
Trace(div(2.0 4.0) #displays '0.5'

My layman's guess is that the output of div matches the input. When I put integers in, I get an integer as output. Is there a way around having to add .0 everywhere? And is there a way to force variables to be floating point?

jsmith45

#3
You can force a value to be floating-point via the "asfloat" command. So if you have an internal variable you can force it to be floating point by including that command before stroing the value in the variable.
For a $variable exposed to the editor, simply make sure the default value is a float, and it should take care of the rest.

Lost in Nowhere

Whenever I try to make a CRPL tower create more CRPL towers, brokenness happens.
For example, this:
Lots of code
Attached to tower
Code (GolehmLoop) Select
# GolehmLoop.crpl
# Created on: 10/9/2013 5:38:32 PM
# ------------------------------------------

$Range:40
$Wait:1800
$HP:12
$MaxDrones:12
$Radius:12
$RotateTime:180 #HAS TO BE A MULTIPLE OF Wait FOR THE ANGLES TO WORK PROPERLY!

once
while CurrentCoords <-Range GetUnitCountInRange eq0
repeat
30 Delay
endwhile
<-MaxDrones 0 do
0 "Drone" I concat ->!
loop
endonce

<-MaxDrones 0 do
"Drone" I concat <-! ->cdrone
<-cdrone "CONST_ISDESTROYED" GetUnitAttribute 1 eq <-cdrone eq0 or if
CurrentCoords "crplcore" CreateUnit ->NewUnit
<-NewUnit "Drone" I concat ->!
<-NewUnit "GolehmDrone" AddScriptToUnit
<-NewUnit "GolehmDrone" "Master" Self SetScriptVar
<-NewUnit "GolehmDrone" "Angle" 360 <-MaxDrones div @degtorad SetScriptVar
<-NewUnit "GolehmDrone" "Radius" <-Radius SetScriptVar
<-NewUnit "GolehmDrone" "RotateTime" <-RotateTime SetScriptVar
<-NewUnit "GolehmDrone" "HP" <-HP SetScriptVar
<-NewUnit "CONST_COUNTSFORVICTORY" 0 SetUnitAttribute
<-NewUnit "CONST_NULLIFIERDAMAGES" 0 SetUnitAttribute
<-NewUnit "CONST_CREATEPZ" 0 SetUnitAttribute
<-NewUnit "CONST_DESTROYMODE" 1 SetUnitAttribute
<-NewUnit "CONST_DESTROYONDAMAGE" 1 SetUnitAttribute
<-NewUnit "CONST_SNIPERTARGET" 1 SetUnitAttribute
<-NewUnit "CONST_SUPPORTSDIGITALIS" 0 SetUnitAttribute
<-NewUnit "CONST_TAKEMAPSPACE" 0 SetUnitAttribute
endif
loop

<-Wait Delay

:degtorad
PI mul 180 div

:destroy
<-MaxDrones 0 do
"Drone" I concat <-! 1 Destroy
loop

Code (GolehmLoop2) Select
# GolehmLoop2.crpl
# Created on: 10/9/2013 5:38:41 PM
# ------------------------------------------

$Range:540
$Speed:2
$Delay1:30
$Delay2:60
$Amount:500
$Amount2:200
$Amount3:100
$Event1D:6
$Event1A:10
$Event2D2:150
$Event2R:5


once
while CurrentCoords <-Range GetUnitCountInRange eq0
repeat
30 Delay
endwhile
CurrentX ->StartX
CurrentY ->StartY
endonce

<-StartX <-Range neg <-Range RandInt add <-StartY <-Range neg <-Range RandInt add <-Speed QueueMove

while GetQueuedMoveCount neq0
repeat
1 Delay
endwhile

50 @Chance if
#Default
<-Delay1 Delay
CurrentCoords <-Amount SetCreeperNoLower
<-Delay2 Delay
else
50 @Chance if
#Event 1
<-Delay1 Delay
<-Event1A 0 do
CurrentCoords <-StartX <-StartY <-Range RandCoordsInRange 2 <-Amount2 CreateSpore
<-Event1D Delay
loop
<-Delay2 Delay
else
#Event 2
<-Delay1 Delay
CurrentX <-Event2R add CurrentX <-Event2R sub do
CurrentY <-Event2R add CurrentY <-Event2R sub do
J I <-Amount3 SetCreeperNoLower
J I 1 SetDigitalisGrowth
J I 1 SetDigitalis
loop
loop
<-Event2D2 Delay
endif
endif

:Chance
0 100 RandInt gte

Not attached to the tower:
Code (GolehmDrone) Select
# GolehmDrone.crpl
# Created on: 10/9/2013 5:38:47 PM
# ------------------------------------------

$Master:0
$Angle:0
$Radius:12
$RotateTime:180
$HP:12

once
<-Angle asfloat @degtorad ->ca
360 <-RotateTime div @degtorad ->step
Self "CONST_MAXHEALTH" <-HP SetUnitAttribute
Self "CONST_HEALTH" <-HP SetUnitAttribute
Self "main" "Custom4" SetImage
Self "second" "Custom1" SetImage
Self "beam" "Custom0" SetImage
Self "main" 2 2 SetImageScale
Self "second" 2 2 SetImageScale
Self "beam" <-Radius 2 SetImageScale
Self "main" -0.2 SetImagePositionZ
Self "beam" -0.15 SetImagePositionZ
Self "second" -0.1 SetImagePositionZ
endonce

<-ca <-step add ->ca
<-ca cos <-Radius asfloat mul <-Master "CONST_XCOORD" GetUnitAttribute add SetCurrentX
<-ca sin <-Radius asfloat mul <-Master "CONST_YCOORD" GetUnitAttribute add SetCurrentY
Self "main" <-ca SetImageRotation
Self "second" <-ca SetImageRotation
Self "beam" <-ca SetImageRotation
Self "beam" <-Master "CONST_XCOORD" GetUnitAttribute CurrentX @avg SetImagePositionX
Self "beam" <-Master "CONST_YCOORD" GetUnitAttribute CurrentY @avg SetImagePositionY

:degtorad
PI mul 180 div
:avg
add 2 div
[close]
is supposed to make the tower move around, emitting creeper and spores, which it does fine, although it occasionally teleports randomly.
However, it is supposed to be surrounded by a bunch of drones to block attacks, which don't even appear.
So, what is the problem with it?
Don't die! :)

albrittbrat

Lost in Nowhere...wow, you are doing alot there. In the map I am working on I have a CRPL tower that makes another CRPL tower and gives it a script to act like a Runner's nest. It works perfectly, but it is nowhere near as complex as what you are trying to accomplish.
I have no idea what '!' does in your drone loop in 'GolehmLoop.crpl'.
I have attached a copy of my two scripts, they might help, but I am not sure. Sounds like an awesome concept though! Look forward to playing your map.
Spoiler


# Primary custom tower code
# If there are no player units within outer digitalis, blue conditions
# If there are player units within outer digitalis, green conditions
# If there are player units within inner digitalis, red conditions
# Changing conditions should change color of creeper on the map
# Outer digitalis bounds: TL(66,66); TR(190,66); BL(66,190); BR(190,190)
# Inner digitalis bounds: T1L(117,98); T1R(139,98)
#                         T2L(98,117); T2R(158,117)
#                         T3L(98,139); T3R(158,139)
#                         T4L(117,158);T4R(139,158)
#-----------------------------------------------------------------------
$range:200
$sleepy:30
@GetClosestUnit ->closestUnit
<-closestUnit neq0 if
<-closestUnit CONST_COORDX GetUnitAttribute ->targetX
<-closestUnit CONST_COORDY GetUnitAttribute ->targetY
else
0 ->targetX
0 ->targetY
endif

#first check to see if there any units in range
<-targetX neq0 <-targetY neq0 and if
#second check to see if X & Y are both between 36 and 220
<-targetX 36 gte <-targetX 220 lte and <-targetY 36 gte and <-targetY 220 lte and if
#third condition to check is if X & Y are both between 66 and 190
<-targetX 66 gte <-targetX 190 lte and <-targetY 66 gte and <-targetY 190 lte and if
#fourth condition to check if X & Y are both between 100 and 156
<-targetX 100 gte <-targetX 156 lte and <-targetY 100 gte and <-targetY 156 lte and if
#Red conditions here, execute if within inner digitalis (kinda)
once
@SetColorRed
#Place a CRPL core to act as a runners nest
"CRPLCORE" CurrentCoords CreateUnit ->unit2
<-unit2 "Mimic Runner.crpl" AddScriptToUnit
<-unit2 "main" "CustomRunnerNest" SetImage
#Seed active digitalis into entire center grid
158 98 do
158 98 do
I J true SetDigitalisGrowth
I J 1 SetDigitalis
loop
loop
endonce
128 128 75 RandCoordsInRange ->randsinRange
<-randsinRange 5 QueueMove
60 Delay
AbortMove
CurrentCoords 250 SetCreeper
#end Red conditions
endif
#Green conditions here, execute if within outer digitalis
once
@SetColorGreen
endonce
#Plant 25 creeper 5 times in random locations
5 1 do
RandCoords 25 AddCreeper
loop
#Launch 1 spore with 1 health, 100 payload at random coordinates
CurrentCoords RandCoords 1 100 CreateSpore <-numb 1 add ->numb
#end Green conditions
endif
#Blue conditions here, execute on outer perimeter of where player units are
#This is more of just a warning with little consequences
once
@SetColorBlue
endonce
CurrentCoords 50 SetCreeper
#end Blue conditions
endif
endif
<-sleepy Delay

#Function to find UID of closest unit
:GetClosestUnit
99999999 ->closestDistance
0 ->closestUnit
CurrentCoords <-range 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
#End of GetClosestUnit function
#Function to change color to dark blue
:SetColorBlue
   GetCreeperColors ->acB ->acG ->acR ->creeperB ->creeperG ->creeperR
   0 ->creeperR
   0 ->creeperG
   60 ->creeperB
   SetCreeperColors(<-creeperR <-creeperG <-creeperB <-acR <-acG <-acB)
#End of SetColorBlue function
#Function to change color to green
:SetColorGreen
   GetCreeperColors ->acB ->acG ->acR ->creeperB ->creeperG ->creeperR
   0 ->creeperR
   160 ->creeperG
   0 ->creeperB
   SetCreeperColors(<-creeperR <-creeperG <-creeperB <-acR <-acG <-acB)
#End of SetColorGreen function
#Function to change color to red
:SetColorRed
   GetCreeperColors ->acB ->acG ->acR ->creeperB ->creeperG ->creeperR
   160 ->creeperR
   0 ->creeperG
   0 ->creeperB
   SetCreeperColors(<-creeperR <-creeperG <-creeperB <-acR <-acG <-acB)
#End of SetColorRed function


#Simple script to mimic a runner's nest
#--------------------------------------
30 ->sleep
GetRunnerCount 15 lte if
CurrentCoords 2 25 100 CreateRunner
<-sleep Delay
endif

[close]

eduran

Quote from: Lost in Nowhere on October 13, 2013, 10:23:00 PM

CurrentCoords "crplcore" CreateUnit ->NewUnit

However, it is supposed to be surrounded by a bunch of drones to block attacks, which don't even appear.

You have to switch the coordinates and the unit type:

"crplcore" CurrentCoords CreateUnit ->NewUnit


No idea what's up with the random teleporting. To me your movement code seems fine.

J

Quote from: Lost in Nowhere on October 13, 2013, 10:23:00 PM
However, it is supposed to be surrounded by a bunch of drones to block attacks, which don't even appear.
So, what is the problem with it?
Add this line:
<-NewUnit "main" "Default" SetImageYou must set an image for a crpl core to appear.

Lost in Nowhere

#8
J, the image is set in the drone script... which doesn't seem to be working anyways.
The drones appear to be being created, but just sit there and have no image. I forgot to mention that whenever the activation code finishes, the boss teleports to the left side of the screen and waits some more for it to start actually doing stuff.
Wiki articles for the <-! and ->! operators.
I'm going to mess around with it a bit to see if I can get it to work...
edit - Managed to get rid of the random teleportation to the left side of the screen.
edit 2 - Just found the issue with the drones - the script name was "GolehmDrone" instead of "GolehmDrone.crpl".
Aaaaaaaaaaaand, now the drones are acting weird...
Don't die! :)

eduran

Two quick questions:
1) Is it possible to pause/unpause the game with CRPL?
2) Is it possible to track player input (mouse clicks/key presses) while the game is paused?

Lost in Nowhere

Is it possible to directly set a unit's position to something that is not an integer?
Don't die! :)

thepenguin

Quote from: eduran on October 15, 2013, 08:12:22 AM
Two quick questions:
1) Is it possible to pause/unpause the game with CRPL?
2) Is it possible to track player input (mouse clicks/key presses) while the game is paused?
yes and no. in that order. The command is PauseGame I know virgil used it in the credits scripts. (It's at the last line)

# CRPLChest.crpl
# Created on: 9/14/2013 2:57:04 PM
# ------------------------------------------

$score:200

once
GetCoresWithVar("name" "Player") pop ->player
endonce

if (Distance(CurrentCoords GetUnitAttribute(<-player CONST_COORDX) GetUnitAttribute(<-player CONST_COORDY)) lte(2))
@ApplyPoints
PlaySound("Retro20")
Destroy(Self 1)
endif

:ApplyPoints
AddAdditionalScore(<-score)
CreateUnit("CRPLCORE" CurrentCoords) ->fadingPoints
AddScriptToUnit(<-fadingPoints "FadingPoints.crpl")
SetScriptVar(<-fadingPoints "FadingPoints.crpl" "pointAmt" <-score)

ClearConversation
AddConversationMessage(7 "You may have noticed that this mission is substantially different from most of the other missions in the game....")
AddConversationMessage(7 "How?  CRPL... Creeper Reverse Polish Language.  That's the scripting language available in CW3.")
AddConversationMessage(7 "Everything from the Gold Man, to his bullets, to the chests... even the walls that Creeper can't overflow.... all implemented using CRPL.")
AddConversationMessage(7 "What's even better is that you can use CRPL to make maps like this or almost anything else you can think up!")
AddConversationMessage(7 "Visit KnuckleCracker.com to learn more about CRPL, and making your own custom maps.")
ShowConversation
PauseGame
We have become the creeper...

Cotters


How do you use the "CreateEffect"? I read the wiki about it, and the example works; but i would like to know how to change the effect.
From wiki:
CreateEffect(14 CellToPixel(CurrentCoords) -1 1.5 1.5 0.05)

I have a feeling it's using effect "0", but I can't figure out how to add in the variable for 1-16 effects.


albrittbrat

Question:
Is there a way to make it so that packets cannot traverse creeper or digitalis, similar to how packets got destroyed when they came into contact with creeper in CW2?
I want to build a maze map, but don't want to have to make 10 wide walls to prevent bridging.

Michionlion

#14
Quote from: Cotters on October 17, 2013, 06:39:43 PM

How do you use the "CreateEffect"? I read the wiki about it, and the example works; but i would like to know how to change the effect.
From wiki:
CreateEffect(14 CellToPixel(CurrentCoords) -1 1.5 1.5 0.05)

I have a feeling it's using effect "0", but I can't figure out how to add in the variable for 1-16 effects.



If you take a look at the CreateEffect wiki page, you missed the vital part.




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'.
"Remember kids, the only difference between science and messing around is writing it down."
                                                                                                                         - Adam Savage

My website
My CW1, and CW2 maps!