Cubescript

From Platinum Arts Sandbox Free 3D Game Maker
Revision as of 10:06, 27 January 2008 by Hirato (Talk | contribs) (Syntax: damn wiki. making me use ascii)

Jump to: navigation, search

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"]]

alias hi [
    say "hi"
    sleep 5000 [
        say "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 tjhe 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 before the results are printed, eg /echo (+ 12 5) will print 17
  • [] is a top level, 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.