Cubescript Tutorial Chapter 1

From Cube Wiki
Revision as of 16:59, 12 December 2014 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

CubeScript Tutorial

Chapter 1: Getting Started

Making a CFG

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 scripts 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 Sauerbraten.

So let’s open up your favorite word processor, right? Not quite yet, as your editor needs to be able to save files as pure text. Word processors, what newbs will be more familiar with, save their contents in special binary files, which Sauerbraten can’t read. Examples are Microsoft Word (*.doc), Apple’s Pages (*.pages), and OpenOffice (*.odt). Most of these can edit and save text files, but they are sluggish apps for the most part that have a lot of useless features for simple text editing. Now that you know what not to use, let’s find something you can. For Windows, most people will use Notepad -- Very exciting. For Linux, there are kate, nano, emacs, and vim. Finally, Mac has TextEdit, which reads and writes most file types. Bean , an open-source offering, is free to download and a very nice balance between features, speed and elegance. Below is a list of apps that you can use, their platform(s), and how to make a CFG (“configuration file”).

(If you have any information on the Windows or Linux sections, please comment in the articles discussion page.)

Windows
Notepad Preinstalled
Notepad++ Download
Linux
kate Depends
nano Depends
To save, press Ctrl-O. To quit, hit Ctrl-X.
emacs Depends
Choose the file name by typing Ctrl-F Ctrl-X (in sequence). Ctrl-X Ctrl-S (in sequence) to save, Ctrl-X Ctrl-C to quit.
vim Depends
Mac OS X
TextEdit Preinstalled
Open TextEdit. Click Format>Make Plain Text or press Command-Shift-T, then press Command-S and choose where to save it and what to call it.
Bean Download
Open Bean. Click File > Save As... > Text (you provide extension) and choose a name (must end in ".cfg")
TextWrangler Download
Smultron Download

1.2 Binds: How To

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 default, 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.

Next Chapter