shohe_i
shohe_i

Reputation: 67

Inform7: How can I create a random chance event in a specific circumstance in inform7?

I would like to make a functionality in my Inform7 game:

When the player decides to go through the crosswalk by going north, in the first time the narrator will indicate to the player that there is a chance that the player will die, and if the player types going north again, then the event will happen and in a randome chance of 1 in 2 succeeds, the player will be able to go to the Garden. Like this:

        Instead of going north in the road for the second time when a random chance of 1 in 2 succeeds:
        say "Yay! You made it!";
        now the player is in the Garden.

        otherwise:
        say "The car crashed you instantly - without any hope, you lost your whole strength in your body…";
        end the game in death.

Yes, this code does not work.. could anyone help me figure out how to make this work?

Upvotes: 1

Views: 552

Answers (1)

Tara McGrew
Tara McGrew

Reputation: 2027

There are two problems with this code:

  1. Inform doesn't allow a when clause after for the second time. (You can write it the other way around, as in "when a random chance of 1 in 2 succeeds for the second time", but that means something different: it would trigger the rule the second time the random chance succeeded, that is, the second time the player survived crossing the road.)

  2. otherwise has to be part of an if statement; it can't be used with a when clause.

To fix the code, you can just move the "random chance" condition into an if statement, then change the punctuation so both alternatives are part of the same rule:

[I added these lines to make a complete example...]
Road is a room.

Garden is a room, north of Road.

Instead of going north in the road for the first time:
    say "The road looks dangerous. You hesitate a moment, unsure if you really want to take the risk."

[And here's the fixed rule:]
Instead of going north in the road for the second time:
    if a random chance of 1 in 2 succeeds:
        say "Yay! You made it!";
        now the player is in the Garden;
    otherwise:
        say "The car crashed you instantly - without any hope, you lost your whole strength in your body…";
        end the game in death.

Upvotes: 5

Related Questions