我想在我的Inform7游戏中实现一个功能:
当玩家决定向北通过人行横道时,第一次解说员将向玩家表明玩家有可能死亡,如果玩家再次键入向北,则事件将发生,并且在1/2成功的随机机会中,玩家将能够前往花园。如下所示:
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.是的,这个代码不能工作..有没有人能帮我弄清楚怎么做?
发布于 2013-05-11 02:31:38
这段代码有两个问题:
for the second time之后使用when子句。(你可以写成相反的方式,比如“当2中有1的随机机会第二次成功时”,但这意味着不同的意思:它将在第二次随机机会成功时触发规则,也就是说,玩家第二次通过road.)otherwise幸存时必须是if语句的一部分;它不能与when子句一起使用。要修复代码,您只需将“随机机会”条件移动到if语句中,然后更改标点符号,以便两个备选方案都属于同一规则:
[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.https://stackoverflow.com/questions/13513892
复制相似问题