Inform7中的嵌套If-Conditions

时间:2017-02-14 13:31:56

标签: inform7

我正在Inform7中实现一个没有任何扩展名的手机。

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";

所以,如果我给爸爸打电话,程序就行了。但如果我打电话给Melissa,她正在回答这个问题,当玩家同意时,整个程序都会失败:

>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
>

1 个答案:

答案 0 :(得分:3)

当你有这种结构时

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

然后,otherwise块将在B未匹配的任何情况下执行。

另一方面,如果你有

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

如果otherwiseA都不匹配,则会执行B块。

所以在你的情况下,你的

if the topic understood matches "Dad":

应该是

otherwise if the topic understood matches "Dad":