Main      Site Guide    
Smash Tutorial

Required Files


The bulk of the code for a Smash game will usually be the location files, that is, one code file for every location you have in your game. You need more than just the location files to get your game working, however. Smash requires certain other files to be present. Here is a list of what those files are and what must go in each.

(Note that all filenames should be in lower case characters. Upper case is disallowed in filenames and, therefore, location names, too.)

Required: game.txt

The game.txt file contains very basic information about your game. The first line of the file must contain the title of your game. This is the only required component of the file.

Lines after the first may be used to set the game's credits, synopsis, difficulty level, and/or Hall of Fame parameters. As long as these lines appear after the first line of the file, they can appear in any order. Each such line starts with one letter and a colon. The various lines of this type that you can have are documented as follows:

Here are some typical game.txt files that you might have with your game:

Sonny Bumpkin's Wild Tractor Ride c:By Samuel Stoddard s:Careen through 16 amazing levels of fun! Dodge s:squirrels and potholes on your race to the chicken farm! h:

Reach For the Stars s:How high can you go? d:4 h:Height h:Crash Landings|n>

Required: start.sma

The start.sma file is a file containing the Smash code that is executed when a new player first starts up a Smash game. Almost any Smash code can appear here. Minimally, there must be a g command, to indicate what location the player starts out in. If there is no g command in your start file, the game will not work.

Frequently the start file will also contain a p command, to display an introduction to the game or some initial instructions to the new players. You might also set the initial values of any global variables or timers that need to be initialized to values other than zero. (All variables are initialized to zero by default.)

You might also use the start file to set initial status lines, or hide certain constant options (see below) that you don't want to be initially available to the player.

Note: You cannot assign state variables in the start file. The reason is that when the start file is executed, the player has not yet been placed at a location within the game (even if you're at a point in the start file that's after a g command!), so there is no location to attach the state variable to. Furthermore, note that if you make use of a scoped state variable within an expression, it will always resolve to zero, because no state variables could have been defined by this point.

Optional: copts.sma

If you want your game to have any "constant options" -- that is, menu options that are (at least mostly) always available, no matter where the player is in the game -- then you must have a copts.sma file where these constant options are defined.

The copts.sma file may only contain constant option blocks and function blocks. A constant option block is a @ command for each constant option and the block of code to be executed when it is selected. Any and all constant options defined in the copts.sma file will be initially visible to the player by default. If you want to have one or more constant options initially hidden from the user, the appropriate @ - commands should be given in the start.sma file.

Note that if you refer to unscoped state variables within a constant option block, it will look at the state variables attached to the current location. Since constant options can typically be chosen from just about any location in the game, this could mean referring to a different variable of the same name each time the option is selected. It's possible you might want to achieve exactly this behavior, but not unless you know what you're doing. In general, don't refer to unscoped state variables from the copts.sma file.

Optional: repeatpre.sma and repeatpost.sma

If you have code you'd like to execute every turn, you can put it in repeatpre.sma or repeatpost.sma, and it'll automatically execute every move. Most games probably won't have a need for these files, but for those games that do, it saves a lot of bug-prone coding to make use of them.

The only difference between the two is when they execute. repeatpre.sma executes after the move code executes but before the location code executes. repeatpost.sma executes after the location code executes. See the page on Program Flow for further information.

Note: You cannot assign state variables in the repeat files.

Optional: admin.sma

admin.sma can be used as a regular .sma file, but it is recommended to reserve its use for a series of debugging or game analysis functions. While not a requirement of the Smash language, some Smash engines provide the ability to load existing saved games, run a function in admin.sma, and display the results -- without saving the existing saved game at all.

This provides game designers with the ability to write functions that figure out where players are in the game. It can be particularly useful when a player wants a hint about what to do next but the author doesn't know what's been done and what hasn't been done. An admin.sma function could be used to check variables and inventory and use the area and/or action description texts to print out information about where the player is in the game and what should be done next.

Optional: objects.txt

If you have any carryable objects in your game (regular objects, not enumerated), then you will need to have an objects.txt file that lists what these objects are. The format of the file is fairly simple. Each line contains information about one item in the game. You need as many lines in the file as there are regular objects in the game.

The contents of the file should look like this:

coin|Gold Coin choc|Box of Chocolates canoe|Wooden Canoe

Each line starts with the object's tag, which is a short string made up of letters, numbers, and/or underscores. It does not matter what this string is, so long as it is different from the object tags of all the other regular objects. For readability, you should pick something that reminds you what the object is. This tag is what you use to refer to the object in your code, for example in a and d commands (which add and drop items from the player's inventory).

After the tag comes a | (an "or bar" or a "pipe"), and then comes the string that will be shown to the player when his current inventory is displayed.

If (and only if) you have an objects.txt file, you will also need an objectactions.sma file that defines what should happen when a player selects one of the items in his inventory:

Optional: objectactions.sma

The objectactions.sma file is a file containing Smash code. Although you can have other code in this file as well, and it can even double as a location within your game, it is strongly recommended, for readability, that you only use this file to store one function for each object in your objects.txt file, which defines what should happen when a player selects an object in his inventory.

Each function should be named after the object tag of a corresponding object. Normally, all these functions should do is display a description of the object. Sometimes you might want to display an image of the object as well. But depending on the needs of your game, you could have other things happen also.

Here is a sample objectactions.sma file for the sample objects.txt file given above:

~ coin p It is shiny. ~ choc p The chocolates look tasty, though perhaps aged a bit beyond the expiration date. Some of them have thumb imprints on the bottom, from when someone tried to sneak a peek at the fillings inside. ~ canoe i canoe.jpg p It's a hefty, unwieldy canoe to be carrying around everywhere you go.

Optional: eobjects.txt

The eobjects.txt file serves the same purpose as the objects.txt file, except for enumerated objects rather than regular objects. Enumerated objects are those objects you can have one or more of. In the example above, we defined "coin" as one of your inventory objects. But if you could, at various points in your game, have one coin, two coins, five coins, or any other number of coins, you can accomplish this by defining the coins as an enumerated object.

The contents of the eobjects.txt file is similar to that of the objects.txt file except that it contains one extra field:

coins|Gold Coin|Gold Coins picks|Guitar Pick|Guitar Picks keyrings|Key Ring|Key Rings

The first field in each line is the tag of the enumerated object, that string which will refer to the object in your Smash code, such as in e commands. The second field is the singular form of the object as it will be displayed to the user. The third field is the plural form. Smash will determine for itself whether it should display the singular form or the plural form at any given time. Note that it doesn't matter whether the tag is singular or plural: it will only ever be used in code, so it doesn't really matter. Technically, the tag doesn't even need to be an English word. You may find it useful, however, to adopt the convention of using plural words for enumerated object tags.

If you have an eobjects.txt file, you must also have a corresponding eobjectactions.sma file, to define what occurs when the user selects an enumerated object from his inventory:

Optional: eobjectactions.sma

Like the objectactions.sma file, the eobjectactions.sma file contains Smash code. Normally, it will just contain one function per enumerated object, each function named with the enumerated object tag of the enumerated object it refers to.

Again, normally you simply want to display a description when a player selects an object from his inventory. Since you can usually have any number of enumerated objects, however, you may find you need a singular version of the description as well as a plural version. To illustrate how you can accomplish this, here's a sample eobjectactions.sma file for the sample eobjects.txt file given above:

~ coins c e:coins = 1 p It is shiny. C p They are shiny. ~ picks c e:picks = 1 p It's just a bit of cheap plastic. C p They're just bits of cheap plastic. ~ keyrings c e:keyrings = 1 p The key ring seems ordinary. It jingles C p They seem ordinary. They jingle P in your pocket every time you take a step. You wonder if the noise is attracting too much attention to yourself. i keyrings.jpg

Optional: lose.txt

If you have a lose.txt file, its contents will be displayed to the player when he does something in the game to cause him to lose -- i.e., whenever an l command is encountered in your Smash code.

The lose.txt can be free-form text, including HTML tags if you wish to use them. Note that the contents of this file will always be displayed when the player loses the game. If you want different things to be displayed based on where and how the player loses, this should be done with action description text (set by p commands).

Within the lose.txt file, you can use []s to display images in the same way that images can be embedded in area and action description texts. You can also use {}s to evaluate expressions; however, note that any functions called with the f: operator within {}s in the lose.txt file may not execute commands that alter the state of the game.

Optional: win.txt

This file works precisely like the lose.txt, except its contents are displayed when the player wins the game.

Within the win.txt file, you can use []s to display images in the same way that images can be embedded in area and action description texts. You can also use {}s to evaluate expressions; however, note that any functions called with the f: operator within {}s in the win.txt file may not execute commands that alter the state of the game.

Optional: hints.txt

If you wish to have hints for your game, you can list a series of questions and answers in a hints.txt file. Whatever hints you supply in this file will be freely viewable by anyone, no matter where they are in the game, so be careful not to supply too many spoilers. The format of the file is fairly simple: separate each problem/hint pair with two hyphens on its own line, and separate a problem from its hint with a blank line. An example follows:

How do I get past the three-armed crazy man? Try finding something that will restrain his deadly whirling limbs. -- I've been to the store, the farm, the amusement park, and the restroom, but I can't find anything that the travelling salesman wants to buy from me! Keep poking around the amusement park. -- Every time I start up the jacuzzi, poison chlorine gas fills the stadium, and everyone dies from asphyxiation! How am I supposed to relax my tense muscles? Try to rig up a mechanical device with the door hinge, the rubber bands, the pillow, the firecrackers, and the honeydipper.

Optional: graphic.gif

If you want your game to have a title graphic, it needs to be a GIF file called graphic.gif. This will be displayed while the game is being played. If you do not supply a graphic.gif file, the Smash engine/interpreter will display the game's title in whatever way it deems appropriate.

Optional: Other Image Files

Obviously you must provide any and all image files that you refer to in the code of your game. These files may be JPG files, GIF files, or PNG files.

Use of images is optional. It's perfectly all right to make a game that does not use any images. But, of course, nice images can add to the flavor of a game.