Lesson 3: Where we learn fancy things like choices, images, and oooh, sound!

Now that you've made a window look like you want, what's next? Well, maybe we want to have the player choose from a set of choices. What would be a good name for that command?

The choice command allows you to present bulleted choices (choices with little dots in front of them), and to pick one, and go to another window or switch based on the choice:

choice "Buy" 3:3
choice "Sell" 3:4
choice "Exit" goto 3:5

GOTO means that you should go to the window or switch with the following bank and entry number. (In a choice, using the word GOTO is optional, because that's all you can do in a choice, really.) We'll talk more about GOTO when we talk about SWITCH statements.

Here is where we reach one of the interesting quirks of APE's evolution. While GOTO is used in a SWITCH to send the code execution to a new WINDOW or SWTICH, it is not an accepted command when used in a WINDOW. To goto another WINDOW or SWITCH at the end of WINDOW, you must use the command NEXTWINDOW. For almost all intents and purposes, it is identical to GOTO.

At the end of this file is a window containing everything from Lesson3. Once you compile it, you can see it all in action.

Okay, this command allows you to add a picture in the window along with the text.

You can include as many images inside the window as you wish. You can use BMPs, PCXs, PNGs, or TGAs each with its own pro/cons:

BMPs Full, 24-bit color, no palette, looks great, but does not support transparency PCXs Transparency (use palette color #255), limited to 256 colors

(PCXs are the usually the handy format for games, because you often want a shape to go over a background looking like its shape, not the shape with a big black square around it. But I digress.)

PNG support was added late to Anachronox. It supports tanslucency, compresses in a lossless format, and is all in all a handy little format. It is heavily used in particles, and interform textures.
The only drawback you may find is that many Windows based viewers, such as Internet Explorer tend to display them either darker or lighter than their original brightness. You should find that Anachronox displays them properly.

TGAs are 24-bit with eight bits of translucency. These allow you to actually have colored, translucent graphics! You can't make these with the Paint program supplied with Windows, but if you have Photoshop or PaintShop Pro, Go ahead!

Here's the format of an image command, and we'll explain each part:


The file can be a PCX, BMP, PNG or TGA and usually is preceded by the pathname to that graphic as well. Otherwise, all the graphics would be sitting in the /GAMEFLOW/ directory! That would stink!

As you might assume from the above statement, the \anoxdata\gameflow/directory is the default directory of the image tag.

NOTE: Use forward slash in all cases in APE. Backward slash, as we'll learn more about later, is used to included special characters, like \n for carriage return.

X,Y are the X and Y coordinate of where in the window to draw the picture. 0,0 is obviously the upper left corner.
H,W are the height and width of the image. These are optional paramaters, and can be used to expand or shrink the image from it's original size.
If a SOLID is specified, text wraps around the picture. If you want the text to go over the picture, or there isn't any text, then don't use SOLID--just specify the filename and the X,Y coordinates. Note that there is a space between the filename and the X,Y coords, not a comma.

If X or Y are negative, it will draw the graphic that much in from the right or lower corner, respectively.

NOTE: Images in Anachronox, must be in powers of 2! What does that mean? It means that images must be in one of the following sizes:
16 X 16
16 X 32
16 X 64
16 X 128
32 X 16
32 X 32
32 X 64
32 X 128
32 X 256
64 X 16
64 X 32
64 X 64
64 X 128
64 X 256
128 X 16
128 X 32
128 X 64
128 X 128
128 X 256
256 X 32
256 X 64
256 X 128
256 X 256

So what if you have a 20 x 45 sized image? Well then, make it 32 x 64 and make the extra space transparent.

This command allows a .WAV file to be played as soon as the window is displayed. This is how we have the speech played in the game. Sounds are stored in
\ANOXDATA\SOUND\ A sound command goes like this:

extern playsound "boots\BOOTS1.WAV"

Okay, here's all those commands used together. Type INVOKE 3:1 after you compile and load it:

NOTE: This lesson used to be much simpler, but the sound command was eventually changed to an extern, which must be run from a switch. So instead of creating an all new lesson, I have simply fixed the old code in an effort to get these docs out asap. So for now, ignore the startswitch and extern commands. They
will be brought in at a later lesson.

#window 2:1
title "Learn 3 Demo" // you can put comments on the same line
body "Choose from three sounds:"
choice "Blip" 2:2
choice "Bleep" 2:3
choice "Bloop" 2:4

#window 2:2
extern playsound "ui/gen/button1.wav"
body "Blip"

#window 2:3
extern playsound "ui/gen/button3.wav"
body "Bleep"

#window 2:4
extern playsound "ui/gen/button4.wav"
body "Bloop"

You should know the drill by now. Compile this and invoke it to see the results.


Okay, in Lesson 4, we're gonna learn about switches...and that gets _reeeally_ interesting!