This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
crpl:crpltutorial [2013/01/23 13:20] – michionlion | crpl:crpltutorial [2020/05/26 18:25] – Added a chapter for Attributes, also fixed a mistake I made earlier Sanian | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ~~DISCUSSION~~ | + | <-[[cw3:creeper_world_3|CW3 Home]]<- [[crpl: |
- | <html>< | + | |
- | < | + | |
- | <- [[crpl: | + | |
====== CRPL Tutorial ====== | ====== CRPL Tutorial ====== | ||
**ATTENTION: | **ATTENTION: | ||
- | <box 60% round green |**Acknowledgements**> | + | |
- | //This tutorial is a contribution by members of the CW3 beta team. Their contributions are gratefully acknowledged// | + | **Acknowledgements** |
+ | //This tutorial is a contribution by members of the CW3 beta team. Their contributions are gratefully acknowledged.//\\ | ||
\\ | \\ | ||
Special thanks to: | Special thanks to: | ||
- | * J | + | * J (for writing the guide) |
- | * Michionlion | + | * Michionlion |
- | </ | + | |
- | + | ||
- | ==== Contents==== | + | |
- | [[crpltutorial# | + | |
- | [[crpltutorial# | + | |
- | [[crpltutorial# | + | |
- | [[crpltutorial# | + | |
- | [[crpltutorial# | + | |
- | [[crpltutorial# | + | |
- | [[crpltutorial# | + | |
- | [[crpltutorial# | + | |
=== Before you start === | === Before you start === | ||
Line 28: | Line 14: | ||
The most important thing that you will need to know is the basics of CW3 gameplay and CW3 editor. It is a good thing if you have programmed before but if that wasn't a stack language it sometimes is a disadvantage. You don't have to have any programming skills to start with [[crpl: | The most important thing that you will need to know is the basics of CW3 gameplay and CW3 editor. It is a good thing if you have programmed before but if that wasn't a stack language it sometimes is a disadvantage. You don't have to have any programming skills to start with [[crpl: | ||
+ | In order to proceed, you will need to know how to get a script to run, including attaching it to a CRPL Core. The collapsed section below contains a button-by-button guide. | ||
+ | |||
+ | < | ||
+ | To do this, you will need a script, such as the following (feel free to copy/paste this): | ||
+ | |||
+ | < | ||
+ | once | ||
+ | ShowTraceLog | ||
+ | "Hello World!" | ||
+ | endonce | ||
+ | </ | ||
+ | |||
+ | To run it: | ||
+ | * Open the editor. | ||
+ | * Press "Edit Map" | ||
+ | * Then " | ||
+ | * And finally " | ||
+ | * Enter a name, and press " | ||
+ | * Press " | ||
+ | * Paste the above script into the text file and save it. | ||
+ | * Return to the editor, and press " | ||
+ | * Note that some text appears. It should say "1 Script successfully compiled into 5 opcodes" | ||
+ | * Create (build) a CRPLCORE (that unfamiliar unit in the lower panel) and select it. | ||
+ | * On the right, there is a drop-down, from which you can select the script you just made. | ||
+ | * Select it and press " | ||
+ | * Unpause the game, and watch the result. You now know how to run scripts. | ||
+ | </ | ||
+ | \\ | ||
==== Starting with CRPL ==== | ==== Starting with CRPL ==== | ||
+ | < | ||
+ | If at anytime you need more practice than given here, go to [[crpl: | ||
+ | </ | ||
- | First of all, if you have programmed before, try to forget that while reading. CRPL is (unlike many others) a stack based language, that means you put (push) all numers | + | First of all, if you have programmed before, try to forget that while reading. CRPL is (unlike many others) a stack based language, that means you put (push) all numbers |
< | < | ||
#this is a comment and will not be executed</ | #this is a comment and will not be executed</ | ||
Line 50: | Line 67: | ||
One more useful functions before I move on to the next section, you can use TIME Delay to stop the execution of the script for the set amount of time. So if you want to add 20 creeper every 3 seconds, you could write: | One more useful functions before I move on to the next section, you can use TIME Delay to stop the execution of the script for the set amount of time. So if you want to add 20 creeper every 3 seconds, you could write: | ||
- | FIXME | ||
<note warning> | <note warning> | ||
- | Time intervals are not seconds, but frames. | + | Time intervals are not seconds, but frames. |
</ | </ | ||
+ | |||
< | < | ||
#first we add the creeper | #first we add the creeper | ||
Line 60: | Line 77: | ||
90 Delay | 90 Delay | ||
</ | </ | ||
- | This of course gives much more possibilities check out this one: | + | |
+ | This of course gives many more possibilities, check out this one: | ||
< | < | ||
CurrentCoords -10 AddCreeper 30 Delay | CurrentCoords -10 AddCreeper 30 Delay | ||
Line 70: | Line 89: | ||
==== Using the tracelog and further introduction of a stack language ==== | ==== Using the tracelog and further introduction of a stack language ==== | ||
- | |||
- | | ||
There' | There' | ||
- | The notation | + | In the examples below we use the following |
- | <box>%%Add (99 33 -- 132)%%</ | + | |
- | < | + | <hidden Show/Hide Examples> |
+ | * Add (99 33 -- 132)< | ||
once | once | ||
- | ShowTraceLog | + | |
- | 99 33 Add Trace | + | 99 33 Add Trace |
endonce | endonce | ||
</ | </ | ||
- | < | + | * Sub (12 7 -- 5)< |
- | %% | + | once |
- | Sub (12 7 -- 5) | + | ShowTraceLog |
- | Mod (15 6 -- 3) | + | 12 7 Sub Trace |
- | %% | + | endonce |
- | </box> | + | </ |
+ | |||
+ | * Mod (15 6 -- 3)< | ||
+ | once | ||
+ | ShowTraceLog | ||
+ | 15 6 ModTrace | ||
+ | endonce | ||
+ | </code> | ||
+ | </ | ||
+ | |||
+ | \\ | ||
You can use multiple operators, but remember that they only pop the last added items from the stack. So where we normally would write (1+2)*(3+4), | You can use multiple operators, but remember that they only pop the last added items from the stack. So where we normally would write (1+2)*(3+4), | ||
- | < | + | |
- | 1 2 add 3 4 add mul</ | + | < |
- | The most important thing here is that you keep in mind that what you've put on the stack last, will be the first you take off (Last In First Out). So < | + | |
+ | The most important thing here is that you keep in mind that what you've put on the stack last, will be the first you take off (Last In First Out). So | ||
+ | |||
+ | '' | ||
+ | |||
+ | will result in | ||
+ | |||
+ | '' | ||
+ | |||
+ | because 5+4=9. If you add another ' | ||
If you want a challenge, read the following piece of code: | If you want a challenge, read the following piece of code: | ||
- | < | + | |
- | ShowTraceLog | + | < |
- | 8 9 5 sub 3 8 mul add 5 7 8 add | + | once |
- | add mod div | + | ShowTraceLog |
- | Trace | + | 8 9 5 sub 3 8 mul add 5 7 8 add |
+ | add mod div | ||
+ | Trace | ||
endonce | endonce | ||
</ | </ | ||
- | Try to guess what's in the trace log | + | |
+ | Try to guess what's in the trace log. | ||
<hidden Click here to see the answer> | <hidden Click here to see the answer> | ||
- | <box left> | + | ^ Operation ^ Stack before ^ Stack after ^ |
- | 8 ( -- 8)\\ | + | |8 |
- | 9 (8 -- 8 9)\\ | + | |9 |8 |8 9 | |
- | 5 (8 9 -- 8 9 5)\\ | + | |5 |8 9 |8 9 5 | |
- | sub (8 9 5 -- 8 4)\\ | + | |sub |8 9 5 |8 4 | |
- | 3 (8 4 -- 8 4 3)\\ | + | |3 |8 4 |8 4 3 | |
- | 8 (8 4 3 -- 8 4 3 8)\\ | + | |8 |8 4 3 |8 4 3 8 | |
- | mul (8 4 3 8 -- 8 4 24)\\ | + | |mul |8 4 3 8 |8 4 24 | |
- | add (8 4 24 -- 8 28)\\ | + | |add |8 4 24 |8 28 | |
- | 5 (8 28 -- 8 28 5)\\ | + | |5 |8 28 |8 28 5 | |
- | 7 (8 28 5 -- 8 28 5 7)\\ | + | |7 |8 28 5 |8 28 5 7 | |
- | 8 (8 28 5 7 -- 8 28 5 7 8)\\ | + | |8 |8 28 5 7 |8 28 5 7 8 | |
- | add (8 28 5 7 8 -- 8 28 5 15)\\ | + | |add |8 28 5 7 8 |8 28 5 15 | |
- | add (8 28 5 15 -- 8 28 20)\\ | + | |add |8 28 5 15 |8 28 20 | |
- | mod (8 28 20 -- 8 8)\\ | + | |mod |8 28 20 |8 8 | |
- | div (8 8 -- 1)\\ | + | |div |8 8 |1 | |
- | Trace (1 -- )\\ | + | |Trace |1 | | |
- | </ | + | |
It will show you the last item on the stack and that is 1. | It will show you the last item on the stack and that is 1. | ||
</ | </ | ||
\\ | \\ | ||
- | Now you should know how the stack and trace and stack system works. You should probably never use the trace functions in custom maps, use it as debug tool. | + | Now you should know how the stack and trace and stack system works. You should probably never use the trace functions in custom maps, but use it as debug tool. |
=== More Examples === | === More Examples === | ||
+ | < | ||
3+9= becomes: 3 9 add | 3+9= becomes: 3 9 add | ||
4*5= becomes: 4 5 mul | 4*5= becomes: 4 5 mul | ||
Line 136: | Line 177: | ||
(16/4)/2= becomes: 16 4 div 2 div | (16/4)/2= becomes: 16 4 div 2 div | ||
16/(4/2)= becomes: 16 4 2 div div | 16/(4/2)= becomes: 16 4 2 div div | ||
+ | </ | ||
If you have problems to visualise it, put the same code in a comment and put brackets around it: | If you have problems to visualise it, put the same code in a comment and put brackets around it: | ||
- | Code: | + | < |
# Send a spore to the top part of the map | # Send a spore to the top part of the map | ||
# CurrentCoords (RandCoords 2 div) (5 4 sub) (2 3 mul) CreateSpore | # CurrentCoords (RandCoords 2 div) (5 4 sub) (2 3 mul) CreateSpore | ||
CurrentCoords RandCoords 2 div 5 4 sub 2 3 mul CreateSpore | CurrentCoords RandCoords 2 div 5 4 sub 2 3 mul CreateSpore | ||
- | Code: | + | </ |
+ | < | ||
# Has a lot of conditions before deciding if the code following must be executed or not | # Has a lot of conditions before deciding if the code following must be executed or not | ||
# ((((0 32 80 GetUnitCountInRange) 1 gte) (<-Eaten 20 gt) and) (GetRunnerCount 20 lt) and) if | # ((((0 32 80 GetUnitCountInRange) 1 gte) (<-Eaten 20 gt) and) (GetRunnerCount 20 lt) and) if | ||
0 32 80 GetUnitCountInRange 1 gte <-Eaten 20 gt and GetRunnerCount 20 lt and if | 0 32 80 GetUnitCountInRange 1 gte <-Eaten 20 gt and GetRunnerCount 20 lt and if | ||
+ | </ | ||
+ | ==== Comparing numbers and conditions ==== | ||
- | === Comparing | + | Sometimes you want a condition to check if code must be executed or not. Like in many other languages, this is possible with the ' |
- | Sometimes you want a condition to check if code must be executed | + | ^ Function ^ Description ^ |
+ | |and|true | ||
+ | |or|true if at least one of the last 2 items are true| | ||
+ | |xor|true | ||
+ | |not|true if the last item is false| | ||
+ | |gt|'greater than', pops 2 items from the stack, | ||
+ | |gte|'greater than or equal'| | ||
+ | |lt|'lower than' | ||
+ | |lte|' | ||
+ | |eq|' | ||
+ | |neq|' | ||
+ | |eq0|true if the last item on the stack is equal to 0| | ||
+ | |neq0|true if the last item is not equal to 0| | ||
- | |||
- | and true if last 2 items are true | ||
- | or true if one of the last 2 items are true | ||
- | xor true if last 2 items are false | ||
- | not true if the last item is false | ||
- | gt ' | ||
- | gte ' | ||
- | lt ' | ||
- | lte ' | ||
- | eq ' | ||
- | neq ' | ||
- | eq0 true if the last item on the stack is equal to 0 | ||
- | neq0 true if the last item is not equal to 0 | ||
- | < | + | Here are some examples: |
- | #These will result in true: | + | |
- | true false or | + | ^ Arg1 ^ Arg2 ^ Operation ^ Result ^ |
- | true true and | + | | false | false | or | False | |
- | true true or | + | | true | false | or | True | |
- | false false xor | + | | true | true | or | True | |
- | false not | + | | true | true | and | True | |
- | 5 5 eq | + | | false | true | and | False | |
- | 1 2 add 3 eq | + | | false | false | and | False | |
- | 4 7 neq | + | | false | false | xor | false | |
- | 9 neq0 | + | | false | true | xor | true | |
- | 9 2 gt | + | | true | true | xor | false | |
- | 6 7 lt | + | | false | |not | True | |
- | 2 2 gte | + | | true | | not | False | |
- | 9 0 mul eq0 | + | | 2 | | eq0 | False | |
- | #These will result in false: | + | | 9 | | neq0 | True | |
- | false false and | + | | 5 | 5 | eq | True | |
- | true false xor | + | | 4 | 5 |eq | False | |
- | true not | + | | 4 | 7 | neq | True | |
- | false false or | + | | 9 | 2 | gt | True | |
- | false true and | + | | 9 | 9 | gt | False | |
- | 9 9 gt | + | | 6 | 7 | lt | True | |
- | 6 4 lte | + | | 5 | 5 | lt | False | |
- | 5 5 lt | + | | 2 | 2 | gte | True | |
- | 4 5 9 add eq | + | | 6 | 4 | lte | False | |
- | 2 eq0 | + | | 1 | 1 | sub neq0 | False | |
- | 1 8 8 div sub neq0 | + | |
- | </ | + | Written as: |
+ | < | ||
- | === More functions === | + | ==== More functions |
Time to learn some more useful commands, I'll take the pre-made towers as example. A function is shown by the function name followed by bracket with the arguments in the order they must be put on the stack, seperated by a ',' | Time to learn some more useful commands, I'll take the pre-made towers as example. A function is shown by the function name followed by bracket with the arguments in the order they must be put on the stack, seperated by a ',' | ||
- | <hidden Emitters: Click to read> | + | <hidden Emitters> |
- | AddCreeper (x, y, amount), adds [amount] creeper to the cell on [x, y]. | + | ^ Command (args) ^ Description ^ |
- | SetCreeper (x, y, amount), sets creeper to [amount] height on cell [x, y]. | + | |AddCreeper (x, y, amount)| adds [amount] creeper to the cell on [x, y]. | |
- | SetCreeperNoLower (x, y, amount), sets creeper to [amount] height on cell [x, y], but it won't remove creeper if there is more creeper than [amount]. | + | |SetCreeper (x, y, amount)| sets creeper to [amount] height on cell [x, y].| |
- | GetCreeper (x, y), gets the creeper of cell [x, y] and puts it on the stack. | + | |SetCreeperNoLower (x, y, amount)| sets creeper to [amount] height on cell [x, y], but it won't remove creeper if there is more creeper than [amount].| |
- | Code: | + | |GetCreeper (x, y)| gets the creeper of cell [x, y] and puts it on the stack.| |
+ | < | ||
# this: | # this: | ||
CurrentCoords 5 SetCreeperNoLower | CurrentCoords 5 SetCreeperNoLower | ||
# does exactly the same as this: | # does exactly the same as this: | ||
- | CurrentCoords GetCreeper 5 lt if | + | CurrentCoords GetCreeper |
- | CurrentCoords 5 SetCreeper | + | 5 lt if |
+ | CurrentCoords 5 SetCreeper | ||
endif | endif | ||
- | #lt means lower than and if decides if the code until endif must be executed or not | + | # lt means lower than and if decides if the code until endif must be executed or not |
+ | </ | ||
</ | </ | ||
- | < | + | |
- | CreateSpore (x start, y start, x destination, | + | < |
+ | ^ Command (args) ^ Description ^ | ||
+ | |CreateSpore (x start, y start, x destination, | ||
< | < | ||
# Send a spore to a random unit | # Send a spore to a random unit | ||
Line 223: | Line 273: | ||
</ | </ | ||
- | + | < | |
- | | + | ^ Command (args) ^ Description ^ |
- | SetTimer0 (time), set the timer of timer 0 to [time], the timers decrease with 1 each game frame. SetTimer1, SetTimer2 and SetTimer3 work the same. | + | |SetTimer0 (time)| set the timer of timer 0 to [time], the timers decrease with 1 each game frame. SetTimer1, SetTimer2 and SetTimer3 work the same.| |
- | GetTimer0 (), pushes the current value of timer 0 on the stack, same thing for GetTimer1, GetTimer2 and GetTimer3 | + | |GetTimer0 ()| pushes the current value of timer 0 on the stack, same thing for GetTimer1, GetTimer2 and GetTimer3.| |
< | < | ||
# Send a spore to a random unit every second | # Send a spore to a random unit every second | ||
Line 237: | Line 287: | ||
# eq0 pops a number from the stack and checks if it is equal to 0 | # eq0 pops a number from the stack and checks if it is equal to 0 | ||
</ | </ | ||
+ | </ | ||
- | == Runner Nest == | + | < |
- | + | ^ Command (args) ^ Description ^ | |
- | GetDigitalis (x, y), checks for Digitalis on cell [x, y] and pushes the health of the Digitalis back on the stack (0 - no Digitalis, 1 - full health). | + | |GetDigitalis (x, y)| checks for Digitalis on cell [x, y] and pushes the health of the Digitalis back on the stack (0 - no Digitalis, 1 - full health).| |
- | CreateRunner (x, y, move, health, payload), creates a runner on position [x, y], the runner has [health] health and moves | + | |CreateRunner (x, y, move, health, payload)| creates a runner on position [x, y], the runner has [health] health and moves [move] |
- | pixels per frame. Once the runner is killed [payload] creeper is deposited. | + | |GetRunnerCount ()| pushes the amount of runner currently on the map created by this CRPL-Core on the stack (exactly the same as GetGlobalRunnerCount, |
- | GetRunnerCount (), pushes the amount of runner currently on the map created by this CRPL-Core on the stack (exactly the same as GetGlobalRunnerCount, | + | |GetGlobalRunnerCount ()| pushes the total amount of runners currently on the map on the stack.| |
- | GetGlobalRunnerCount (), pushes the total amount of runners currently on the map on the stack | + | < |
- | Code: | + | |
# Create a weak runner every frame if Digitalis is present and less than 20 runners are on the map | # Create a weak runner every frame if Digitalis is present and less than 20 runners are on the map | ||
CurrentCoords GetDigitalis neq0 GetGlobalRunnerCount 20 lt and if | CurrentCoords GetDigitalis neq0 GetGlobalRunnerCount 20 lt and if | ||
- | CurrentCoords 2 5 5 CreateRunner endif | + | |
+ | endif | ||
+ | </ | ||
+ | </ | ||
- | More Digitalis stuff: | + | < |
- | A CRPL-Core | + | A CRPL-Core |
- | GetDigitalisGrowth (x, y), checks for digitalis growth area at cell [x, y], if Digitalis can grow there, 1 is pushed back on the stack, if not, 0 is pushed back on the stack. | + | ^ Command (args) ^ Description ^ |
- | SetDigitalis (x, y, health), sets the health of the digitalis on cell [x, y] to [health], 0 removes the Digitalis while 1 sets the D to full health. | + | |GetDigitalisGrowth (x, y)| checks for digitalis growth area at cell [x, y], if Digitalis can grow there, 1 is pushed back on the stack, if not, 0 is pushed back on the stack.| |
- | SetDigitalisGrowth (x, y, present), sets if Digitalis can grow on cell [x, y]. Present must be 0 (no Digitalis growth area) or 1 (creates growth area). | + | |SetDigitalis (x, y, health)| sets the health of the digitalis on cell [x, y] to [health], 0 removes the Digitalis while 1 sets the D to full health.| |
+ | |SetDigitalisGrowth (x, y, present)| sets if Digitalis can grow on cell [x, y]. Present must be 0 (no Digitalis growth area) or 1 (creates growth area).| | ||
< | < | ||
- | #this code is mostly used in moving towers | + | # this code is mostly used in moving towers |
- | #leave a trail of Digitalis growth area and set the digitalis to full health | + | # leave a trail of Digitalis growth area and set the digitalis to full health |
CurrentCoords true SetDigitalisGrowth | CurrentCoords true SetDigitalisGrowth | ||
CurrentCoords 1 SetDigitalis | CurrentCoords 1 SetDigitalis | ||
</ | </ | ||
+ | </ | ||
- | === Variables and Loops === | + | \\ |
+ | ==== Variables and Loops ==== | ||
A variable: a way to store numbers without using the stack once stored. | A variable: a way to store numbers without using the stack once stored. | ||
You can use -> | You can use -> | ||
- | Code: | + | |
+ | < | ||
16 ->mynumb | 16 ->mynumb | ||
2 ->n2 | 2 ->n2 | ||
Line 273: | Line 329: | ||
while <-mynumb < | while <-mynumb < | ||
<-mynumb <-n2 div endwhile | <-mynumb <-n2 div endwhile | ||
+ | </ | ||
- | As you may have noticed, I used ' | + | As you may have noticed, I used ' |
- | A do loop has 2 functions and has the following form: | + | |
- | do (limit, index) loop | + | Lets start with a ' |
- | ' | + | |
- | Code: | + | '' |
- | #Add 5 creeper to 5 random locations every 5 seconds | + | |
+ | ' | ||
+ | |||
+ | < | ||
+ | # Add 5 creeper to 5 random locations every 5 seconds | ||
5 ->times | 5 ->times | ||
5 -> | 5 -> | ||
150 ->wait | 150 ->wait | ||
- | <-times 0 do RandCoords < | + | <-times 0 do |
+ | | ||
+ | loop | ||
+ | <-wait Delay | ||
+ | </ | ||
There' | There' | ||
- | while repeat (execute) endwhile | + | |
+ | '' | ||
When while is read, the code between while and repeat is executed (and should push true or false on the stack). If true is read, the code will be executed until endwhile and execution return to while. If false is read, the code between repeat and endwhile is skipped and the execution continues at endwhile. | When while is read, the code between while and repeat is executed (and should push true or false on the stack). If true is read, the code will be executed until endwhile and execution return to while. If false is read, the code between repeat and endwhile is skipped and the execution continues at endwhile. | ||
- | Code: | + | |
- | #Add 5 creeper to 5 random locations every 5 seconds | + | < |
+ | # Add 5 creeper to 5 random locations every 5 seconds | ||
5 ->times | 5 ->times | ||
5 -> | 5 -> | ||
150 ->wait | 150 ->wait | ||
0 ->numb | 0 ->numb | ||
- | while <-numb 4 lte repeat RandCoords < | + | while <-numb 4 lte repeat |
- | #lte means lower than or equal | + | |
+ | endwhile | ||
+ | <-wait Delay | ||
+ | # lte means lower than or equal | ||
+ | </ | ||
In a do or while loop, you can use ' | In a do or while loop, you can use ' | ||
- | Code: | + | |
+ | < | ||
#Add 5 creeper to 5 random locations every 5 seconds | #Add 5 creeper to 5 random locations every 5 seconds | ||
5 ->times | 5 ->times | ||
Line 304: | Line 377: | ||
150 ->wait | 150 ->wait | ||
0 ->numb | 0 ->numb | ||
- | while true repeat RandCoords < | + | while true repeat |
+ | | ||
+ | endwhile | ||
+ | <-wait Delay | ||
#' | #' | ||
#and the loop will keep going until break is read | #and the loop will keep going until break is read | ||
#this can easily make your game crash if you don't add the break command! | #this can easily make your game crash if you don't add the break command! | ||
#gt means greater than | #gt means greater than | ||
+ | </ | ||
- | Defining your own functions: | + | ====Defining your own functions==== |
If you want to use the same piece of code multiple times or want a better overview, you can use functions. In the main code, use @FUNCTION to call the function. At the end of the code, use :FUNCTION to define the function. The function is the piece of code between :FUNCTION and the end of the script or another function. If you want to give arguments or return a value, use the stack. An example to help you: | If you want to use the same piece of code multiple times or want a better overview, you can use functions. In the main code, use @FUNCTION to call the function. At the end of the code, use :FUNCTION to define the function. The function is the piece of code between :FUNCTION and the end of the script or another function. If you want to give arguments or return a value, use the stack. An example to help you: | ||
- | Code: | + | < |
@getnumb #pass the execution to :getnumb | @getnumb #pass the execution to :getnumb | ||
@emit #pass the execution to :emit | @emit #pass the execution to :emit | ||
Line 323: | Line 400: | ||
5 #push 5 on the stack | 5 #push 5 on the stack | ||
#end of the code, the :getnumb function stops here | #end of the code, the :getnumb function stops here | ||
+ | </ | ||
+ | |||
And how it looks without comments: | And how it looks without comments: | ||
- | Code: | + | |
+ | < | ||
@getnumb @emit | @getnumb @emit | ||
# | # | ||
Line 330: | Line 410: | ||
->numb CurrentCoords <-numb AddCreeper | ->numb CurrentCoords <-numb AddCreeper | ||
:getnumb 5 | :getnumb 5 | ||
+ | </ | ||
- | Making your script more useful: | + | ====Attributes==== |
+ | |||
+ | CRPL allows you to modify the attributes of units, which is arguably the most powerful feature of CRPL. Unit attributes may look very complicated but they' | ||
+ | ^ Function ^ Description ^ | ||
+ | |Self () |Pushes the UID of the current unit on the stack| | ||
+ | |GetUnitAttribute (unit UID, attribute) |Finds the unit with the given UID, gets the given attribute and pushes | ||
+ | |SetUnitAttribute (unit UID, attribute, value) |Finds the unit with the given UID and sets the given attribute to the given value| | ||
+ | |||
+ | Each attribute has a number. The ' | ||
+ | |||
+ | Here's a short list with //some// of the attributes you can use (more can be found on the [[crpl: | ||
+ | |||
+ | ^ Attribute ^ Description ^ Value ^ | ||
+ | | CONST_COORDX | The x coordinate of the unit. |0| | ||
+ | | CONST_COORDY | The y coordinate of the unit. |1| | ||
+ | | CONST_AMMO | The unit's ammo. Floating point value. |17| | ||
+ | | CONST_COUNTSFORVICTORY | Whether the CrplTower must be destroyed before map victory on annihilation game modes. Only works for CRPLTowers. |27| | ||
+ | | CONST_CREATEPZ | Whether the CrplTower creates a power zone when destroyed. Only works for CRPLTowers. |21| | ||
+ | | CONST_HEALTH | The unit's health. Floating point value. |15| | ||
+ | | CONST_MAXAMMO | The unit's max ammo. Floating point value. |18| | ||
+ | | CONST_MAXAMMOAC |The unit's max AntiCreeper ammo. Floating point value. |10| | ||
+ | | CONST_MAXHEALTH | The unit's max health. Floating point value. |16| | ||
+ | | CONST_NULLIFIERDAMAGES | Whether the CrplTower can be targeted and damaged by Nullifiers. Only works for CRPLTowers. |18| | ||
+ | |||
+ | Remember that simply typing an attributes name doesn' | ||
+ | |||
+ | If this is still a bit hard to follow, here's an example: | ||
+ | |||
+ | < | ||
+ | : | ||
+ | # GetUnitsInRange first pushes the UIDs of all units in range, then the amount of units | ||
+ | # If there are no units in range it pushes 0 on the stack | ||
+ | CurrentCoords 10000 GetUnitsInRange -> | ||
+ | |||
+ | 0 < | ||
+ | |||
+ | < | ||
+ | I <-unitNr eq if # if unit is the chosen one | ||
+ | CONST_ISBUILDING true SetUnitAttribute | ||
+ | else pop endif | ||
+ | loop | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====Making your script more useful==== | ||
If you use $VARNAME: | If you use $VARNAME: | ||
- | Code: | + | |
+ | < | ||
$amtToEmit: | $amtToEmit: | ||
$interval: | $interval: | ||
- | |||
CurrentCoords < | CurrentCoords < | ||
< | < | ||
- | Take a look at '$interval:15'. When you attach the script to a core in-game you can choose a value for the variable 'interval'. If you don't input a number in-game, | + | </ |
+ | Take a look at '$amtToEmit:10'. When you attach the script to a core in-game you can choose a value for the variable 'amtToEmit'. If you don't input a number in-game, | ||
This is a very powerful mechanism to use the same script over different cores or if you want to give the script to other map makers. | This is a very powerful mechanism to use the same script over different cores or if you want to give the script to other map makers. | ||
+ | You should use it instead of | ||
+ | < | ||
+ | where possible. Also try to use this instead of fixed values (10 AddCreeper), | ||
+ | |||
+ | |||
+ | ==== Useful links==== | ||
+ | CRPL reference with all available functions: | ||
+ | [[: | ||
- | Useful links: | + | Guide to [[examine map resources]] to extract scripts and custom images from another map. |
- | A page filled with functions and examples: | + | If you need more practice or help to a common problem, you might be able to find it at the [[:crpl:CrplTutorial: |
- | http:// | + | |
- | The KC wiki with a CRPL overview and reference: | + | This wiki page is largely based off of a guide on the KC forums, some changes have been made however. The original guide on the KC forums: |
- | http:// | + | http:// |