You are on page 1of 2

Cubescript Tutorial

1. Hello World!!!
These two words represent the start of a new programming language. Hello World i
s the most basic exercise in any programming language, cubescript is no differen
t.
The echo command. Especially useful in single player game making, the echo comma
nd prints a line (or more) in the console visible only to its executor.
The format for the echo command is:
echo "TEXT TO ECHO HERE"
pretty simple.
Therefore our hello world script is:
echo "Hello World"
Try adding this line to your autoexec.cfg file and see what happens.
2. Saying Hello to the World
Echoing Hello World isn't really very practical in multiplayer situations. Sure
it looks neat but noone else can see it. So now we delve into the say command.
Format:
say "Text to say"
this will send the "Text to say" just like if we had pressed "t" and typed it.
To say hello world add the following to autoexec.cfg:
say "Hello World!"
3. OK...
If you executed the last script (Suspicious look towards reader) you might have
noticed that your say command executed when you started the game, and therefore
basically said "Hello World" To yourself.
Now this is not really useful until we introduce binds.
Binds allow you to make a key on the keyboard execute one or more commands.
Format:
bind "KEY HERE" [COMMANDS TO EXECUTE; SEPARATED WITH Semicolon]
You might notice that I used brackets ([]) for the commands. This is mearly for
ease of use, and the brackets could be "" or () just as easily.
So how would I say "Hello World!" whenever I press the "F1" Key?
Script:
bind "F1" [say "Hello World!"]
Thats right! You should know what to do with this script by now.
4. HELP!!! I'VE RUN OUT OF KEYS!!!!!
Fortunately for the excessive binder, we have GUIs (Graphical User Interfaces).
GUIs allow us to execute commands without having to remember those pesky key bin
ds (its a real pain to press KILL when you meant to taunt).
To make a gui, simply use the command newgui.
guibuttons are just like buttons on the built in sauer menus. They execute comma
nds.
Format:
guibutton "TEXT TO DISPLAY" [commands to execute]
So...How would I make a gui that says "HELLO WORLD!!!!" ???
Code:
newgui HelloWorld[
guibutton "Hello World" [say "Hello World"]
]
WTF! It doesn't do anything!! :@
ah... sorry you need to display the gui before you can use it.
The easiest way to do this is with binds.
So:
bind "F1" [cleargui; showgui HelloWorld]
newgui HelloWorld[
guibutton "Hello World" [say "Hello World!!!!!"]
]
HORRAYY!!! You have made your first gui.
5. Aliases...
Aliases unlike you first might suspect are simply "Variables" (this term is used
very loosely)
Most correctly the format for an alias is:
alias VARIABLE [COMMANDS; TEXT; NUMBERS; ETC]
However for the lazy among us there is a easier aproach:
VARIABLE = [COMMANDS; TEXT; NUMBERS; ETC]
So how would I fit this in with the Hello World Theme?
Good Question! Try the following line of code:
hw = [say "Hello World"]
Now in sauerbraten simply press "/" then type hw (Your command should be /hw)
If you've done it right, you should say hello world.
Its that simple.
I hope I have gotten you started on the Cube Scripting Path
Just a note: Hello World was just a example of the limitless possibilities now a
vailable to you. I hope you will experiment, examine other people's scripts via
Quadropolis, and ask others for aide.

You might also like