Inform7技术问题:如何让NPC收到物品后执行检视动作
解决Inform 7中NPC接收物品后不执行检视动作的问题
你遇到的核心问题是自定义的After giving规则没有触发NPC的检视动作,连报告规则都没响应——这大概率是规则优先级或者动作触发条件的问题。下面是一步步的排查和修复方案:
1. 提升规则优先级,避免被默认规则覆盖
Inform 7的规则系统会按优先级执行,默认的After giving规则可能会抢先覆盖你的自定义逻辑。你可以用Last after强制让你的规则最后执行,确保它能生效:
Last after giving the book to Tom: try Tom examining the book.
2. 确保物品已成功转移到NPC手中
虽然After giving理论上是在物品转移完成后触发,但特殊场景下可能存在物品未及时归属NPC的情况。你可以添加条件,确保动作只在Tom真正拿到书后触发:
Last after giving the book to Tom when the book is carried by Tom: try Tom examining the book.
3. 用force跳过动作检查(如果try失效)
默认的try会触发动作的Check规则,可能某些隐形限制(比如NPC默认不会主动执行动作的隐含逻辑)阻止了检视动作。这时候可以用force跳过所有检查,直接强制执行:
Last after giving the book to Tom: force Tom to examine the book;
4. 修正报告规则的匹配范围
确保你的报告规则能准确匹配场景,避免因语法限制导致不触发:
Report Tom examining the book: say "Tom takes the book, flips through its pages, and mutters, 'Interesting...'.";
完整可运行示例
把这些逻辑整合起来,完整代码如下:
The Library is a room. Tom is a man in the Library. The tattered book is a thing. It is carried by the player. Last after giving the tattered book to Tom when the tattered book is carried by Tom: force Tom to examine the tattered book; Report Tom examining the tattered book: say "Tom takes the tattered book, runs a finger over its cover, and starts flipping through the pages slowly.";
测试时输入give book to Tom,就会先显示默认的交付文本,紧接着触发Tom的检视动作并输出你自定义的报告内容。
内容的提问来源于stack exchange,提问作者D. Grimshaw
相关产品推荐
相关产品推荐

