Constant Story "INFORM BEGINNER'S GUIDE"; Constant Headline "^A Tutorial^by <your name here>^"; Include "Parser"; Include "Verblib"; Object BoringRoom "Boring Room" with name "baseboard" "wood" "panelling" "panel", description "This room is empty. There is nothing here but the wood panelling on the walls and the baseboard."; [Initialise; location = BoringRoom; "^^^^^^Oh man, this is too much already! What's with the ~Constant,~ ~Include,~ ~Initialise,~ and all that other stuff? I thought we were going to take it slow...!^"; ]; Include "Grammar";
| ||
Be sure you write Initialise, not Initialize. |
Now save your file and run it through the compiler. You'll have to refer to the compiler's documentation for how to do that (sorry). Create a version 5 file. Once you have a story file created, play it with your interpreter. Once again, you're on you're own here, but it shouldn't be difficult.
There is no light source, so you were in darkness. To fix this, change the end of the room description to look like this:
wood panelling on the walls and the baseboard." has light;
Now recompile and run. Really. No tricks this time. Try anything you can think of. If you get anywhere, let me know, because you sure shouldn't be able to.
Constant Story "INFORM BEGINNER'S GUIDE"; Constant Headline "^A Tutorial^by <your name here>^";
Let's look at an example which would work in Inform. Suppose you implement a system where the player can carry a maximum weight. For the sake of example, let's make this weight 100. Let's also say that you refer to this weight in 8 different places in your source code. Then you decide that this maximum lets the player carry too much; you want the value to be 75. If you typed the value 100 every time you dealt with the maximum weight, you would now have to change this 100 to 75 in each of the 8 places it occurs. While this could be done with your editor's find and replace feature, what if you used the value 100 somewhere else for something that had nothing to do with maximum weight? This would also get changed to 75! The answer, then is to define a constant (MAX_WEIGHT comes to mind) to represent the maximum weight and use the constant in those 8 places. Then you would simply change this
Constant MAX_WEIGHT 100;
to this
Constant MAX_WEIGHT 75;
and you're done. It's basically a programming tradition to write constants in all capital letters. The idea behind this is that nothing else should be written in all caps, and therefore whenever you see something in all caps, it's got to be a constant. I find the idea sound and use it myself. It's a free country, folks (at least it is where I live), so do whatever you want.
Notice also the use of the characters ~ (tilde) and ^ (circumflex). These characters have a special meaning to the compiler. The tilde, when used inside a string, tells the compiler to put a quotation mark (") in the game file. Why can't you type a quotation mark directly? Because it marks the beginning and end of the string, so if you entered
"What's with the "Constant" and "Include," stuff?"the compiler would flag an error and refuse to create a game file, because it thinks the string ends at "the " and then it tries to interpret "Constant" as some action to take (which it is, just not here). The only thing the compiler expects to find at the end of a string being printed is a comma (and then more things to print) or a semicolon.
The circumflex means "start a new line." It's like pressing the Enter key (or Return, for you Mac folks). When the interpreter reads this character during the course of the game, it continues printing at the beginning of the next line (or prints blank lines if there are more than one). This character also stands for an apostrophe (') when used in object names. More on that later.
Include "Parser"; Include "Verblib";
You should also be aware that although the compiler will eventually find an error in your file when a semicolon is dropped off the end of a statement, it doesn't always report that specific line as being the cause of the error, because it doesn't know there's a problem until it runs into things later that it didn't expect. Therefore, when you get a whole slew of errors when compiling, look at the first line it indicates an error on (in your source file) and back up a little bit. See if you can find a statement that's missing its terminator.
Object BoringRoom "Boring Room" with name "baseboard" "wood" "panelling" "panel", description "This room is empty. There is nothing here but the wood panelling on the walls and the baseboard." has light;
Oh boy, do we ever have some fun stuff here! Remember how I said that the two main parts of an I-F game are objects and the things you do to/with them? Well, here's an object. It even says so: Object. What more do you want?
Altogether, the first line of an object's definition is called the object header.
Imagine a variable as a box with a label on it.
The label on the box is the variable's name. No two boxes in the same place can have the same label. What does "in the same place" mean? I'll get to that. The box can contain anything. I mean it, anything. Imagine that it expands to hold a value of any size. Therefore it could contain a number, a single character, or a whole chapter of a book. It could also contain a reference to an object, an action, or other things we haven't covered yet.
You can change the value of the variable whenever you want, as long as you're "in the same place." (I'll get to that, really I will.) You change the value by specifying the name of the variable (the label), an equals sign (=), and the new value. This can mess with your mind if your only experience with variables has been in math class. For example, let's say you've created a variable called x. You give x the value of 10:
x = 10;
Now let's add 1 to the value of x:
x = x + 1;How can this be? How can something be equal to itself plus 1? The answer is that we are not making a statement of fact that x is equivalent to itself plus 1; rather we are taking the current value of x, adding 1 to it, and assigning the result back to x. x now contains 11.
You can also assign the value of another variable to the first one.
x = y; x = z * 4; x = y + z;All these examples deal with variables that contain numeric values. Variables containing text or object references will be dealt with later.
A constant is even a special type of a variable, an "unchanging variable," oxymoron though that may be. Think of a constant as being a glass box with its lid locked. You can see the value inside, and therefore use it, but you can't open the lid to put something else in. However, I will try really hard to refer to constants as constants throughout this guide.
Variables must be declared before they can be used. Sometimes, as in the case of objects, the variable (actually a constant, see below) is declared and assigned at the same time. Other, standalone variables must be explicitly declared, either in the header of a routine or with the Global directive. This brings us to "in the same place."
To simplify things, let's say that a variable can either be accessible (I'll use the term "visible" from here on) anywhere in your file or only in certain parts. All objects (and hence their constants) are visible anywhere in the file. All variables declared as global are visible anywhere in the file. All constants are global, and thus visible anywhere in the file. Variables declared within routines are visible only between the brackets ([]) that frame the rountine. I haven't introduced routines yet, so just remember that when we get to them. I will of course mention it again and give examples to clarify.
About the only time you wouldn't give an object a constant is when you are creating something that will not be referred to anywhere else in your code. The best rule of thumb as far as I'm concerned is to name a constant for each object. Definitely give all rooms constants, or you'll never be able to get the player into them!
Short description
Next comes "Boring Room". This is known as the object's short
description. In the case of a room, the short description is used as a header
when printing out the long (Look) description, as a complete description when
returning to a room that's already been visited (assuming the VERBOSE command has
not been given), in the title bar to indicate the current room, and when the PLACES
and OBJECTS commands are used.
For an non-room object, the short description is printed in inventory lists, room descriptions ("You see a <...> here"), and the OBJECTS command. There are ways that you can step in and print your own text instead of letting the compiler print the short description. That's for later.
After the short description optionally comes a constant indicating the parent of an object. In truth, the object's constant and short description are optional, too. (There is also another way of indicating an object's parent by using arrow notation after the word Object, but I find this rather difficult to read. I like it spelled out right in front of my face that the parent of Toilet is Bathroom.) Rooms don't have parents, so no constant is included here. This is basically what makes a room a room.
Let's talk about that...
And yes, folks, it's really free. I'm too cheap to pay for this.