inform7

Nested If-Conditions in Inform7


I am implementing a phone in Inform7 without any extension.

Calling is an action applying to one topic.
Understand "Call [text]" or "[text] call" as calling.
Carry out Calling:
    if the topic understood matches "Melissa":
        say "You are calling Melissa … 'are you fine?'";
        if player consents:
            say "good???";
        otherwise:
            say "I see!";
    if the topic understood matches "Dad":
         say "Hey boy";
    otherwise:
        say "beeeeep – [the topic understood] is not answering";

So if I call Dad the procedure works. But if I call Melissa, she is answering the question and when the player consents, the whole procedure fails:

>call melissa
You are calling Melissa … 'are you fine?'
yes
good???
beeeep -  
*** Run-time problem P39: Attempt to say a snippet value which is currently invalid: words 2 to 2.

  is not answering
>

Solution

  • When you have this construction

    if A
       ...
    if B
       ...
    otherwise
       ...
    

    Then the otherwise block will be executed in any case that B was not matched.

    On the other hand, if you have

    if A
       ...
    otherwise if B
       ...
    otherwise
       ...
    

    then the otherwise block will be executed if neither A nor B was matched.

    So in your case, your

    if the topic understood matches "Dad":
    

    should be

    otherwise if the topic understood matches "Dad":