{{ message }}

# hikari-no-yume / schnitzelVerse

Cannot retrieve contributors at this time
85 lines (83 sloc) 4.9 KB
 schnitzelVerse - script help

schnitzelVerse - script help

back to schnitzelVerse

schnitzelVerse has a small stack-based scripting language. This means variables, strings and numbers are added to a stack, and then pulled off by commands, for example:

10 20 "hello" !textat

10 is pushed on the stack. 20 is pushed on the stack. "hello" is pushed on the stack. !textat pops all three off the stack, and draws the string "hello" at (20,10).

A more complex example:

10 20 + "20 + 10 = " . !print

10 and 20 are placed on the stack. The + operator pops 20 and 10 off the stack, adds them and places the result (30) on the stack. "20 + 10 = " is pushed onto the stack. The . operator pops "20 + 10 = " off the stack and 30 off the stack, concatenates them and places the result ("20 + 10 = 30") on the stack. !print pops "20 + 10 = 30" off the stack and displays it.

Operators

• + adds 2 numbers, e.g. 20 10 + results in 30
• - subtracts 2 numbers, e.g. 20 10 - results in -10
• * multiplies 2 numbers, e.g. 3 10 * results in 30
• / divides 2 numbers (integer division, no floating point), e.g. 5 12 / results in 2
• . concatenates two strings/numbers, e.g. ", world" "hello" results in "hello, world"
• % divides 2 numbers and returns the remainder (modulo), e.g. 2 7 % results in 1
• = sets a variable, e.g. "hello, world" x = sets x to "hello, world"
• & gets the variable with a given name, e.g. "y" & 3 = is equivalent to just y 3 =. This is useful for algorithmically setting/getting values.

Variables

You can reference a variable's value by naming it. You can set a variable's value with the = operator. Along with user-defined variables, there are also the following built-ins:

• playerX - player's X position
• playerY - player's Y position
• playerXRel - player's X position relative to object (useful for graphics)
• playerYRel - player's Y position relative to object
• playerNick - player's nickname
• objectX - object's X position
• objectY - object's Y position
• objectWidth - object's width
• objectHeight - object's height
• msecs - milliseconds since 00:00 1 January 1970, useful for animation, time, etc.

Functions

• !print - displays text on the next line (line reset by !clear), e.g. "hello, world" !print would display hello, world on the next line
• !color - sets drawing color (used by !print, !textat, !clear, !boxat), can be any CSS color (rgb(r,g,b) format, #RRGGBB, named colors...) e.g. "orange" !color would set the color to orange
• !font - sets font style, follows CSS font property syntax, e.g. "bold 12pt Arial" !font sets the font to 12pt size bold Arial, "10pt sans-serif" !font sets the font to 10pt size with the system default sans-serif font
• !clear - resets !print line position and clears background with current drawing color
• !boxat - draws filled box with given width height, pops x, y, width, then height off stack (hence you need to do [height] [width] [y] [x] !drawbox), e.g. 100 150 10 20 !boxat draws a 150x100 box at (20, 10)
• !textat - draws text at specified position, pops text, x, then y off stack (hence you need to do [y] [x] [text] !textat), e.g. 10 20 "hey" !textat draws the text hey at (20, 10)
• !sin - working with degrees, returns the value for 1000sin(x), (i.e values between -1000 and 1000), e.g 90 !sin results in 1000, 180 !sin results in 0, 225 !sin results in -707
• !cos - same as !sin but for cosine, e.g. 180 !cos results in -1000

Examples

Glowing Square

This forms a CSS color string of the rgb(r, g, b) based on the time. It sets the value of the red component by calculating sin((time / 20)) * 127 + 127, and then clears the canvas with that color.

msecs 20 / val =
127 val !sin 127 * 1000 / val =
127 val + val =
"rgb(" rgb =
val rgb . rgb =
",0,0)" rgb . rgb =
rgb !color
!clear

Scoreboard

"rgb(79,97,80)" !color
!clear

"10pt sans-serif" !font
"black" !color

"purple" !color
20 objectWidth 18 0 !boxat
"white" !color
"bold 10pt sans-serif" !font
"1. us" !print

"black" !color

"2. them" !print
"3. someoneelse" !print
"4. somebody" !print

"" !print

"10pt sans-serif" !font playerNick "your nick is " . !print

You can’t perform that action at this time.