Saturday, February 9, 2019

Future Events in Inform 7

One of the neat things I like to do is a puzzle that requires the solution in a certian number of turns. The way I do this is by using future events. This is covered in The Inform Book in chapter nine.

The typical syntax for an event in the future is Amazing thing happens in five turns from now. This sets the event to happen, however, you also have to describe what happens when that event actually happens. This is done with the At the time when Amazing thing happens: syntax. Here's a sample of that for a very simple task.

The Empty Art Gallery is a room. "It looks like someone took all of the art in here."

When play begins:
    Amazing thing happens in four turns from now.

At the time when amazing thing happens:
    say "All of the art suddenly appeared!".
    
Test me with "wait/wait/wait/wait/wait".

However, there's only one room here, let's see what happens when I add another room that doesn't have anything to do with the art reappearing.

The Empty Art Gallery is a room. "It looks like someone took all of the art in here."
The parking lot is a room. "This is a very empty parking lot several blocks form the art gallery."

The parking lot is west of the empty art gallery.

When play begins:
    Amazing thing happens in four turns from now.

At the time when amazing thing happens:
    say "All of the art suddenly appeared!".
    
Test me with "wait/west/wait/wait/wait".

Test it out with Test me and you will see that you're standing in the parking lot and the art appeared! Now there's several ways to solve this, the best one is to create an object called Art and then place it in the room after so many turns. Then on the first time you see it, be surprised. However, I'm not going to get that involved right now. Instead I'll just do a simple if statement.

The Empty Art Gallery is a room. "It looks like someone took all of the art in here."
The parking lot is a room. "This is a very empty parking lot several blocks form the art gallery."

The parking lot is west of the empty art gallery.

When play begins:
    Amazing thing happens in four turns from now.

At the time when amazing thing happens:
    if the player is in The Empty Art Gallery:
        say "All of the art suddenly appeared!";
    otherwise:
        say "For some reason you thought about all of the art.".
    
Test first with "wait/west/wait/wait/wait".
Test second with "wait/wait/wait/wait/wait".

Now you get a different bit of text depending on your location. I know this is a very basic example, but it demostrates the basic scheduling of tasks. In this case the timer begins as soon as the game starts, but you can also schedule the event when entering or leaving a room, talking to a person, or picking up an item. That last one is always fun!

No comments:

Post a Comment

Implementing Help in a Story