Difference between revisions of "Cubescript"

From Platinum Arts Sandbox Free 3D Game Maker
Jump to: navigation, search
(some more stuff)
m (kiddy stuff)
Line 112: Line 112:
 
loops are used to quickly execute code, and are usually invoked with /loop. the loop is invoked as such /loop alias value-to-stop-at [commands to execute] eg /loop i 10 will loop it 10 times, each time it'll increase i by one. The example will also demonstrate a use of format. which can take up to 10 arguments. the first is the string of text, and the subsequent stuff are what'll replace %1 %2 %3 %4 %5 %6 %7 %8 and %9 respectively. You would've also noticed that the executed function like - + div etc is at the beginning of the (). and not inbetween the two values like we're normally used to. if you want to see the original when there's 100 bottles, use /conskip -99 to go to the top of the history.
 
loops are used to quickly execute code, and are usually invoked with /loop. the loop is invoked as such /loop alias value-to-stop-at [commands to execute] eg /loop i 10 will loop it 10 times, each time it'll increase i by one. The example will also demonstrate a use of format. which can take up to 10 arguments. the first is the string of text, and the subsequent stuff are what'll replace %1 %2 %3 %4 %5 %6 %7 %8 and %9 respectively. You would've also noticed that the executed function like - + div etc is at the beginning of the (). and not inbetween the two values like we're normally used to. if you want to see the original when there's 100 bottles, use /conskip -99 to go to the top of the history.
  
loop i 100 [say (format "%1 bottles of beer on the wall, %1 bottles of beer" (- 100 $i))]
+
loop i 100 [say (format "%1 bottles of juice on the wall, %1 bottles of juice" (- 100 $i))]
  
you should see similiar at the top of your screen by executing that
+
you should see similar at the top of your screen by executing that
  
Sandboxer: 5 bottles of beer on the wall, 5 bottles of beer<br>
+
Sandboxer: 5 bottles of juice on the wall, 5 bottles of juice<br>
Sandboxer: 4 bottles of beer on the wall, 4 bottles of beer<br>
+
Sandboxer: 4 bottles of juice on the wall, 4 bottles of juice<br>
Sandboxer: 3 bottles of beer on the wall, 3 bottles of beer<br>
+
Sandboxer: 3 bottles of juice on the wall, 3 bottles of juice<br>
Sandboxer: 2 bottles of beer on the wall, 2 bottles of beer<br>
+
Sandboxer: 2 bottles of juice on the wall, 2 bottles of juice<br>
Sandboxer: 1 bottles of beer on the wall, 1 bottles of beer<br>
+
Sandboxer: 1 bottles of juice on the wall, 1 bottles of juice<br>

Revision as of 17:56, 27 January 2008

Cubescript is the scripting language utilised within the sauerbraten/cube2 engine. it is used to set aliases, variables, create binds and generate the menu.

List of commands

These are just a list of commands, what they actually do will be covered a bit later in this topic.

General

The following commands are quite often used in a lot of scripts.

  • alias
  • at
  • do
  • getalias
  • getname
  • getteam
  • if
  • listlen
  • loop
  • result
  • sleep
  • while

Binds

The following commands are useful in binds.

  • onrelease

Gui Creation

These commands are used to create various menus.

  • cleargui
  • guibar
  • guibutton
  • guicheckbox
  • guifield
  • guiimage
  • guilist
  • guirolloveraction
  • guirollovername
  • guistayopen
  • guitab
  • newgui

Alias/command comparing and changing

  • +
  • -
  • *
  • /
  • !
  • =
  • >
  • <
  • div
  • mod
  • strcmp
  • strstr

String/text formatting

These commands are used to format aliases which are normally huge bits of text

  • concat
  • concatword
  • format

Shaders

All of the nice graphical effects were programmed in ASL (assembly shading language), and formatted in cubescript themselves.

Writing in Cubescript

Syntax

Cubescript has many similarities with C, mostly in the way the script is formatted. there's a few key differences, a new line means a ; was placed at the end of a line automatically. so placing on yourself is good practice, but unnecessary. note the examples below do the exact same thing.

one liner example

alias hi [say "hi"; sleep 5000 [say "Hi again"]]

multi liner example

alias hi [
    say "hi"
    sleep 5000 [
        say "Hi again"
    ]
]

it's obvious what the above code does, it'll make your character say hi, and wait 5 seconds before saying hi again.

indenting is done in levels, the Tabulator (TAB) key is usually used to indent the text. while not necessary, it tends to make it bigger, and more legible as seen in the above example (when you get to big stuff, you'll thank yourself for indenting it.

As a rule of thumb, pretty much only [ increases the indentation level. Also note, ", ] and ) can close each other, so make sure you close them off properly

statement enclosers

While not the correct name, by statement enclosers, I mean the bits of ascii you usually use to enclose text with. Which is "" [] and () in cubescript. They all perform different functions too.

  • "" is used when you wish to make it print exactly what you typed in it, eg /echo "Hi, my name is John Smith"
  • () is used when you want the stuff inside it to be executed. and the results given eg /echo (+ 12 5) will print 17
  • [] is the top level one, and should be used when you plan to use either () or "" inside your statement. eg echo [is that "cheese"?]. This is used mostly compared to the rest.


Examples

Loops

loops are used to quickly execute code, and are usually invoked with /loop. the loop is invoked as such /loop alias value-to-stop-at [commands to execute] eg /loop i 10 will loop it 10 times, each time it'll increase i by one. The example will also demonstrate a use of format. which can take up to 10 arguments. the first is the string of text, and the subsequent stuff are what'll replace %1 %2 %3 %4 %5 %6 %7 %8 and %9 respectively. You would've also noticed that the executed function like - + div etc is at the beginning of the (). and not inbetween the two values like we're normally used to. if you want to see the original when there's 100 bottles, use /conskip -99 to go to the top of the history.

loop i 100 [say (format "%1 bottles of juice on the wall, %1 bottles of juice" (- 100 $i))]

you should see similar at the top of your screen by executing that

Sandboxer: 5 bottles of juice on the wall, 5 bottles of juice
Sandboxer: 4 bottles of juice on the wall, 4 bottles of juice
Sandboxer: 3 bottles of juice on the wall, 3 bottles of juice
Sandboxer: 2 bottles of juice on the wall, 2 bottles of juice
Sandboxer: 1 bottles of juice on the wall, 1 bottles of juice