Showing posts with label Events. Show all posts
Showing posts with label Events. Show all posts

Saturday, February 16, 2019

Using a variable with future events

So I had mentioned variables before in this post. So here is a quick example of using a variable, it will also show off the every turn rule.

The moment it gets hot is a time that varies.
The moment it gets hot is initially 7:35 PM.

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:
    Now the time of day is 7:31 PM;
    The heat cranks in three turns from now.

Every turn:
    If the time of day is before the moment it gets hot:
        say "Such a nice day.";
    otherwise:
        say "The heat is unbearable.".
        
At the time when the heat cranks:
    Say "I think the heat is cranking up.";
    Increase the moment it gets hot by 3 minutes.
    
Test me with "z/z/z/z/z/z/z/z".

Now if you want to play around with it, you can compare how long you have to wait before the moment it gets hot to this.

The moment it gets hot is a time that varies.
The moment it gets hot is initially 7:35 PM.

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:
    Now the time of day is 7:31 PM.
    [The heat cranks in three turns from now.]

Every turn:
    If the time of day is before the moment it gets hot:
        say "Such a nice day.";
    otherwise:
        say "The heat is unbearable.".
        
[At the time when the heat cranks:
    Say "I think the heat is cranking up.";
    Increase the moment it gets hot by 3 minutes.]
    
Test me with "z/z/z/z/z/z/z/z".

As you can see I commented out the the heat cranks scheduled event. So the time variable that holds when the moment it gets hot never increases by three minutes.

Now you'll notice that I'm using minutes and setting explictly the time here. This is Inform time and pretty much every action, even just standing there, costs one minute. However, you can create rules that alter the default cost of time per move. You can even create rules that have some actions cost no time what-so-ever. You can see an example of this from the Recipie Book in Chapter 4 with Timeless.

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!

Implementing Help in a Story