checking player input

I’m writing a game where the player has to interact with a phone. I need them to be able to dial a number, but the only number that I care about them being able to dial is “911.”

So all I need the phone to do is be something that they can use or dial (I created a dial action) and then prompt them to input a number. Then I just need to check that input, and if it is equal to “911” or “9 11” or “9 1 1” or other variations, print some dialog and transition to another level.

Alternatively, maybe they could “talk” to the phone? I don’t want the player to have a list of dialog options though, or any clue about what number they should dial. It should be clear from the context and I don’t want to be hand-holdey.

I’m very new to Inform 7 and I’m really struggling with this. Any suggestion would be greatly appreciated!

I think your original method is just fine: a dialing action for DIAL 911 which prints up a canned cutscene.

Off the top of my head (untested), if you only want them to be able to dial 911, you need to provide a sensible response to any other number. If you define your new action like this:

Calling-911 is an action applying to nothing. Understand “911” and “call 911” and “dial 911” as calling-911.

…then you’re not going to get a smooth in-game response if the player types ‘call 411’. You need an action of the form:

Calling-number is an action applying to one number. Understand “[number]” and “call [number]” and “dial [number]” as calling-number.

But I’ll bet you a nickel that’s not the right way to do it, and a quick glance through the TOC for the chapter on Advanced Actions reveals nothing about using numbers as input to actions. There’s an example in the Recipe Book on using a telephone … but it doesn’t seem, on a quick skim-read, to tackle this obviously important issue.

Short answer: I don’t know.

–JA

You could side-step the issue and make the calling action apply to a topic. It’s equally possible that the players type something like “call police” or “call for help” or “call home”.

UPDATE:

I’ve almost got it working.

@Jim Aikin: Thanks! I used your second suggestion to get as far as I have with this!

@Juhana: Thanks for the suggestion. I really only want the action to succeed if they get 911 though. It’s an important transition in the game and I don’t want anything about the action to be vague or generic.

The scene begins with the phone off the hook. There is a phone cradle object and a phone receiver object.
The code for “dial [number]” is:

Dialing is an action applying to one number. Understand "dial [number]" as dialing.

The code looks like this for the dialing action:

Instead of dialing when the player does not carry the receiver: if receiver has not been on cradle, say "You can't dial the number without reseting the call."; if receiver is on cradle, say "You can't dial a number without picking up the receiver."; else say "How do you expect to make a call without holding the receiver?"; Instead of dialing when the player does carry the receiver: if receiver has not been on cradle: say "test, fail to reset call."; stop the action.; if number is 911, say "test, number success."; else say "test, number fail.";
Everything works fine except the most important part-- whatever number the player dials by using the command “dial [number]” leads to a success. Something is failing when it hits the “if number is 911, say “test, number success.”;” line, and I can’t figure out what it is. Why is every number causing a success?!

Thanks for the help!

I haven’t tested this, but I think you want “If the noun is 911” – “the noun” is (usually?) the direct object of the command, so it’ll be whatever number was entered. “If number is 911” I think checks whether 911 is a number, which is always true.

That’s not what I meant. Other input should be taken into account, otherwise you get misleading error messages:

Optimally you’d want something like this:

(Also, if you requre a certain wording it’s important to clue the player in really carefully, especially in this case because 911 is not used outside North America.)

“If the number understood is 911.” Noun refers always to things, never to values.

UPDATE:

I fixed the problem!

... Instead of dialing when the player does carry the receiver: if receiver has not been on cradle: say "[placeholder]test, fail to reset call."; stop the action.; if the player's command does not match "dial 911": say "[placeholder]number fail"; stop the action; if the player's command matches "dial 911": say "[placeholder]success."; move player to Dream #1.
Now if the player gets the right number, it transitions, and if they get the wrong number they get feedback that explains the situation.

@Juhana I’ve avoided using call for a reason, to narrow the input to numbers. I also have put in a “mistake” for the dial action, so that if someone types in [text] they will receiver an error. I will probably put in a rule to handle if the player attempts to “call,” probably something like “If you want to call someone, you need to dial a number first.”

Thanks for the reminder that we only use 911 in North America. I’ll have to decide what I’m going to do about that. My phone also has .ogg sounds, all of which are local to North America. I’ll have to think about some way of cluing in the player that is not from NA.

Oops. Thanks.