Cubescript Tutorial
CHAPTER 1: GETTING STARTED
1.1 Making a CFG file
The most basic part of a script is having a file to run it in. Of course you can simply type it in the console on-the-fly, but sripts can get very complex. Trying to type in an entire script, or even copy-and-paste it into the console simply won’t work even in slower games than Cube/Sauerbraten (I’ll just say one or the other from now on, whatever’s easier).
So let’s open up your favorite text editor, right? Not quite yet. Your editor needs to be able to save files as pure text. Most big system editors, most likely the ones newbs will be more familiar with, save their contents in special binary files, which Cube can’t read. Examples are Micro$oft Word (.doc), Apple’s Pages (.???), Appleworks (.cwk), and OpenOffice (.???).
Now that you know what not to use, let’s find something you can. For Windoze, there’s Notepad. Very exciting. For Linux, there’s kate, nano, emacs, and vim. Finally, most Mac users have Xcode, which reads and writes source code files, naturally in plain text; TextEdit also works, but you can’t creat plain text (.txt) files, only read them. Below is a list of apps that you can use, their platform(s), and how to make a cfg (“configure file”).
Notepad
Windows
(I work on a Mac, so I don't know how to use these first few. If you know how,
please edit this page.)
kate
Linux
nano
Linux
emacs
Linux
vim
Linux
Xcode
Mac OSX
Open Xcode (if you installed the developer tools, it’s in Developer/Applications; if you didn’t install it, find the disc and do so). Choose New File from the File Menu, and then choose plain text file in the box that pops up. Name it myfirstscript.cfg, and save it to your Sauerbraten/sauerbraten folder (“sauerbraten folder” from now on).
TextEdit
Mac OSX
In Finder, duplicate an existing cfg in your sauerbraten folder. Rename it myfirstscript.cfg, then open it with TextEdit.
So make your cfg.
1.2 Binds: Howto
bind “W” [forward]
bind “W” [ forward ]
bind W [forward]
bind W “forward”
These four lines show the two ways you can assign (bind) a key to a certain command. (I prefer the first or second or even third, since they appear to be more in line with the rest of Cubescript’s style; I’ve included the fourth so you can recognize it.) This tells Cube you want to move forward when you press “w” on your keyboard. Most keys will already be assigned in Sauerbraten/sauerbraten/data/defaults.cfg (defaults.cfg from now on), so you don’t have to worry about most of them.
You can assign any command to any available key (see section 1.4 for all key names). If I named a script “hello” and I wanted to assign it to the left shift key, I’d add
bind “LSHIFT” [hello]
to autoexec.cfg in my sauerbraten folder; if autoexec.cfg doesn’t already exist, you can simply make one like you did in 1.1.
By defaul, jumping is bound to your right mouse button (MOUSE2). You might like this; however, other games usually have jumping bound to the spacebar. If you want to keep all your movement keys in one place, and your shooting keys on your mouse, you can switch some stuff around. (Currently, both left click and the spacebar are jump; however, this is still a good exercise.)
So what do you do? Well, the key name (SPACE) and the command (jump) are fairly obvious, and you know how to make simple binds, so go ahead and try it. Remember to place your customizations in autoexec.cfg so that Cube will remember them if you ever need to delete config.cfg (a common fix for many problems).
You should end up with something like
bind “SPACE” [jump]
Now left click is free to bind a “zoom script” to. You’ll make your first script, a zoom, in 2.1.
NOTE:
In defaults.cfg, you will see some lines that look like this:
editbind “SPACE” [ cancelsel; passthroughsel 0 ]
As you can see, it’s some sort of bind. But editbinds only apply while you’re in edit mode. This is delicate territory, so we’ll learn about editbinds much later on. For now, don’t touch any of them.
1.3 Some basic commands for common use
Here are some commands you’ll need fairly often:
These five should be fairly obvious:
- forward
- backward
- left
- right
- jump
- "thirdperson X" turns thirdperson view on and off (X equalling 1 and 0, respectively)
- "fov X" changes your field of vision to any number between 150 and 50 degrees (100 is default in Sauerbraten, 90 in most other games)
- "hudgun X" shows your gun in-game (1) or hides it (0)
- "hidehud X" shows your hud (heads-up-display) (0) or hides it (1)
- "screenshot" takes a screenshot as a .bmp and saves it to your sauerbraten folder
- "say X" used by a script to say a comment, such as “good game”, for you
- "taunt" performs the taunt animation in-game
- "map X" loads map X
- "mode X" changes the mode for the next map to X
- "echo X" is used by a script to tell only you something, such as warnings, map information, or a story in singleplayer
- "//" is used to start a comment line in a script
1.4 Bind: Key names reference
See
this page for a complete list of the keys you can bind in Cube II.