Main      Site Guide    
Smash Tutorial

Sample Adventure: The Trainer

The "tree.sma" File


This file handles the location in the game where the player starts out -- by the tree with the rope hanging in it. There's not much the player can do here unless he has the rock, and then he can throw it up at the rope. The first two times he does this fail, but on the third the rope comes falling out of the tree. Let's examine this file one piece at a time.

. The path, which comes from the south, loops around a tall tree here. There doesn't appear to be anywhere else to go. You gaze at the tree in wonder, awestruck by its size. c a:rope , What do you want to do? C , As you admire it, you notice a rope hanging from some high branches. What do you want to do?

The above section of code is a pretty common thing to do. The . command displays a generic description of the area, and then text is appended to the generic description with , commands depending on what the specific circumstances are. Here, we always say that there's a path to the south and a large tree. Then, if the player has not picked up the rope yet, we also mention that there's a rope in the tree.

The next section of code continues within the earlier C block, so it, too, will only execute if the rope is still in the tree. (We don't, after all, want to provide the player with the option of throwing the rock at the rope if the rope isn't even in the tree anymore.)

c a:rock * 1 Throw your rock at the rope. s times_thrown + 1 c times_thrown = 3 p You hit it! The rock dislodges the rope from the treetop. Both fall down on the ground; you retrieve them. a rope C times_thrown = 1 p You toss the rock at the rope, but it misses. You retrieve the rock. Well, you know what they say. If at first you don't succeed, try, try again! C p You toss the rock at the rope, but it misses. You retrieve the rock. Well, you know what they say. If at second you don't succeed, try, try again!

First, we check to make sure that the player still has the rock. If so, we allow him to throw the rock at the rope. If he does so, we increment a state variable called "times_thrown" which keeps track of how many times he's thrown it so far. Once fails. Twice fails. The third time, he gets the rope. Note that we do not have to handle the case where the rock is thrown four or more times, because after the third, we won't ever display this option again.

The rest of this file, which follows, is pretty simple. We provide an option to climb the tree, which results in failure every time, and an option to circle the tree, which doesn't do anything helpful. Finally, we allow the player to go south to the location called "rock."

* 2 Climb the tree. p You get part way up but fall back down. * 3 Circle the tree. p It's fun to walk around in circles, isn't it? ^ s Go south. g rock