Skip to content
Go to file
Cannot retrieve contributors at this time
85 lines (83 sloc) 4.9 KB
<!doctype html>
<meta charset=utf-8>
<title>schnitzelVerse - script help</title>
<h1>schnitzelVerse - script help</h1>
<a href=/>back to schnitzelVerse</a><br>
<p>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:</p>
<p><code>10 20 "hello" !textat</code></p>
<p>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).</p>
<p>A more complex example:</p>
<p><code>10 20 + "20 + 10 = " . !print</code></p>
<p>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.</p>
<li>+ adds 2 numbers, e.g. <code>20 10 +</code> results in 30
<li>- subtracts 2 numbers, e.g. <code>20 10 -</code> results in -10
<li>* multiplies 2 numbers, e.g. <code>3 10 *</code> results in 30
<li>/ divides 2 numbers (integer division, no floating point), e.g. <code>5 12 /</code> results in 2
<li>. concatenates two strings/numbers, e.g. <code>", world" "hello"</code> results in "hello, world"
<li>% divides 2 numbers and returns the remainder (modulo), e.g. <code>2 7 %</code> results in 1
<li>= sets a variable, e.g. <code>"hello, world" x =</code> sets x to "hello, world"
<li>& gets the variable with a given name, e.g. <code>"y" & 3 =</code> is equivalent to just <code>y 3 =</code>. This is useful for algorithmically setting/getting values.
<p>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:</p>
<li>playerX - player's X position
<li>playerY - player's Y position
<li>playerXRel - player's X position relative to object (useful for graphics)
<li>playerYRel - player's Y position relative to object
<li>playerNick - player's nickname
<li>objectX - object's X position
<li>objectY - object's Y position
<li>objectWidth - object's width
<li>objectHeight - object's height
<li>msecs - milliseconds since 00:00 1 January 1970, useful for animation, time, etc.
<li>!print - displays text on the next line (line reset by !clear), e.g. <code>"hello, world" !print</code> would display <code>hello, world</code> on the next line
<li>!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. <code>"orange" !color</code> would set the color to orange
<li>!font - sets font style, follows CSS font property syntax, e.g. <code>"bold 12pt Arial" !font</code> sets the font to 12pt size bold Arial, <code>"10pt sans-serif" !font</code> sets the font to 10pt size with the system default sans-serif font
<li>!clear - resets !print line position and clears background with current drawing color
<li>!boxat - draws filled box with given width height, pops x, y, width, then height off stack (hence you need to do <code>[height] [width] [y] [x] !drawbox</code>), e.g. <code>100 150 10 20 !boxat</code> draws a 150x100 box at (20, 10)
<li>!textat - draws text at specified position, pops text, x, then y off stack (hence you need to do <code>[y] [x] [text] !textat</code>), e.g. <code>10 20 "hey" !textat</code> draws the text <code>hey</code> at (20, 10)
<li>!sin - working with degrees, returns the value for 1000sin(x), (i.e values between -1000 and 1000), e.g <code>90 !sin</code> results in 1000, <code>180 !sin</code> results in 0, <code>225 !sin</code> results in -707
<li>!cos - same as !sin but for cosine, e.g. <code>180 !cos</code> results in -1000
<h3>Glowing Square</h3>
<p>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.
<p><code>msecs 20 / val =<br>
127 val !sin 127 * 1000 / val = <br>
127 val + val =<br>
"rgb(" rgb =<br>
val rgb . rgb =<br>
",0,0)" rgb . rgb =<br>
rgb !color<br>
<p>This displays a simple leaderboard.</p>
<p><code>"rgb(79,97,80)" !color<br>
"10pt sans-serif" !font<br>
"black" !color<br>
"leaderboard test (fake)" !print<br>
"purple" !color<br>
20 objectWidth 18 0 !boxat<br>
"white" !color<br>
"bold 10pt sans-serif" !font<br>
"1. us" !print<br>
"black" !color<br>
"2. them" !print<br>
"3. someoneelse" !print<br>
"4. somebody" !print<br>
"" !print<br>
"10pt sans-serif" !font playerNick "your nick is " . !print
You can’t perform that action at this time.