Interactive Fiction – How do I …?

Q. How do I have random outcomes?

Q. How do I get the player to be able to brush their teeth?

Q. How do I keep a player from doing something for a certain number of turns?

Q. How do I have two different descriptions for a room, one for the first visit and one for the subsequent visits?

Q. How do I prevent everything in a room being listed after the room description?

Q. How do I find examples of code and syntax for new ideas?

 

Q. How do I have random outcomes?
A. Here is an example I made that shows a use of random outcomes:

The dog park is a room.  “A large field with room for chasing a ball.”
A ball is in the dog park. “A bouncy ball, small enough to catch, but to large to swallow.”
Shadow is an animal.  Shadow is in the dog park.  The description of Shadow is “A black dog with a happy demeanor.”.

Shadow’s score is a number that varies.

After taking the ball when a random chance of 1 in 5 succeeds:
    say “The ball is rather wet, and you wish you had brought your gloves.”.

After dropping the ball:
    if a random chance of 2 in 3 succeeds:
        say “Shadow catches the ball.”;
        increase Shadow’s score by 1;
        if Shadow’s score > 5:
            say “‘Shadow keeps the ball and lies down”;
            now Shadow carries the ball;
        otherwise:
            say “Shadow drops the ball at your feet ready for another round” ;
            now the ball is in the park;
    otherwise:
        say “Shadow looks for the ball and finally gets it after it lands on the ground.”;
        now the ball is in the park.

 

Q. How do I get the player to be able to brush their teeth?
A. Below is a copy of some code where this was answered on this forum: http://rec.arts.int-fiction.narkive.com/uveoqKBk/i7-newbie-with-simple-question

Bathroom is a room.

a toothbrush is in Bathroom.
the description is “It’s an Oral-B.”.

understand “brush”as the toothbrush.

brushing is an action applying to one thing.
understand “brush [something]” as brushing.
understand “brush [teeth]” as brushing.

the teeth is a thing.
the teeth is a part of the player.
the teeth is either brushed or unbrushed.
the teeth is unbrushed.

before brushing the teeth for the first time:
          if the toothbrush is carried by the player begin:
                    now the teeth is brushed;
                    say “You brush your teeth. They become sparkly and clean once again.”;
                   stop;
          otherwise;
                    say “What are you going to use? Your finger?”;
                    end if.

before brushing the teeth:
          if the teeth is brushed:
                    say “You’ve already brushed your teeth.”;
                    stop.

before sleeping:
          if the teeth is unbrushed begin;
                    say “You need to brush the old choppers before sacktime.”;
                    stop;
          otherwise;
                    say “You hit the sack in preparation for tomorrow’s grueling activities.”;
                    stop;
          end if

 

Q. How do I keep a player from doing something for a certain number of turns?
A. There are also many ways to crack this nut … I used a counter variable to tackle it:

Waiting room is a room.  The description of the waiting room is “A grand room with only one place to stand while you wait.  The person in the booth to the north tells you to enjoy peace and quiet while you wait.”.

x is a number that varies.  x is 0.

every turn:
    if player is in waiting room:
        if x is 0:
            say “As you look around you realize that you are going to need to wait for a while, ‘Better practice some deep breathing exercises’, you mumble to your self and your aching feet.”;
            increase x by 1;
        if x is less than 5:
            say ” …”;
            say “Waiting can actually be relaxing, at least that is what you keep telling your feet.”;
            increase x by 1;
        if x is 5:
            say ” …”;
            say “At last you can move on into the booth to the north.”;
            increase x by 1;            
        if x is greater than 5:
            say ” …”;
            say “The booth to the north appears ready for you.”.        
                
Booth is a room.  The booth is north of the waiting room.

instead of going to booth:
    if x is less than 6:
        say “You need to wait you turn!”;
    otherwise:
        continue the action.

Note:  For a simpler situation you could use something like this ..

Every turn:
    if the player has been in the Waiting room for 5 turns, say “After a happy beep is heard, your name is called and you can have your turn.”….

Q. How do I have two different descriptions for a room, one for the first visit and one for the subsequent visits?
A. Below is some modified code I found in the playfic tutorial by Cooper http://playfic.com/games/cooper/tutorial

The Cave is west of the Corridor.
The description of the cave is  “[if the Cave is unvisited] Good job! The next room is to the east. So just enter the letter ‘e’ to go east? [end if][if the Cave is visited] You are in the Cave. The Corridor is to the east and the Entrance is to the south.[end if]“.

Q. How do I prevent everything in a room being listed after the room description?
A. The best way I have found so far is to use the extension: Mentioned in Room Description by Ron Newcomb.  I found it particularly useful for supporters …

Include Mentioned in Room Description by Ron Newcomb.

Kitchen is a room.  “The kitchen is a wonderful place full of treats.  Sometimes there are treats on the [table.]”

A table is in the kitchen.  The table is fixed in place.
A cookie is on the table. The description of the cookie is “Chocolate chip”.
The chips are on the table.  The description of the chips is “Plain.”

Try running this sample code with the extension and without, you will see the difference.  It is similar to to the “omit contents in listing” for containers from lesson 3.

NOTE: Be careful with this one!  If you include removable items in a description and a player removes the item, the next time they enter the room the old description will be displayed. 

Q. How do I find examples of code and syntax for new ideas?
A. The built in documentation is quite good for examples.  This site is great for looking through syntax and finding new ideas: http://inform7.com/learn/documents/I7_syntax.txt

Leave A Reply

Your email address will not be published. Required fields are marked *