You need to enable JavaScript to run this app. Inform7 if条件未生效:特定时段开放睡眠的昼夜循环开发问题
优惠活动
大模型
产品
解决方案
定价
更多

Inform7 if条件未生效:特定时段开放睡眠的昼夜循环开发问题

Inform7 睡眠机制条件失效问题解答

附:提问原文与原始代码

我是一名刚接触Inform7的开发新手,在探索引擎可实现的功能边界的过程中获得了很多乐趣。目前我结合可获取的线上教程,尝试为交互作品加入昼夜循环与睡眠交互机制,设计为仅在某一夜间时段向玩家开放睡眠功能。但我目前遇到了开发障碍:Inform7没有按照设定执行编写的if判断语句,导致玩家在一天中的任意时段都能触发睡眠,不符合设计预期。我清楚自己刚入门,很可能是忽略了一些基础细节,希望能得到大家的帮助,找到问题的修复方案,非常感谢。
我的代码可能存在疏漏,毕竟我是抱着学习心态的新手,还请大家多多谅解。以下是我编写的全部代码:

The sun is a backdrop. It is everywhere. The description is "Currently out of sight."

Night is a recurring scene. Night begins when play begins. Night begins when the time of day is 10:00 PM. Night begins when Dusk ends. Night ends when the time of day is 1:30 AM.

When Night begins:
    say "The moon is up and the temperature drops abruptly to well below zero.";
    now the description of the sun is "Currently out of sight."

The witching hour is a recurring scene. The witching hour begins when Night ends. The witching hour ends when the time of day is 5:00 AM.

When The witching hour begins:
    say "You feel sleep calling you.";
    now the description of the sun is "Currently out of sight."

Day is a recurring scene. Day begins when The witching hour ends. Day ends when the time of day is 6:00 PM.

When Day begins:
    say "The sun is now properly up."

Dusk is a recurring scene. Dusk begins when Day ends. Dusk ends when the time of day is 10:00 PM.

When Dusk begins:
    say "The sun is setting."

A person is either awake or asleep. A person is usually awake.

Every turn: 
    if The witching hour is not happening:
instead of sleeping when the player is awake:
    now the player is awake; 
    say "You can't sleep now. . ."

Every turn:
    if The witching hour is happening:
instead of sleeping:
    now the player is asleep;
    say "You fall asleep. . ."

Every turn:
    if The witching hour is happening:
instead of doing something other than waking up, waiting or sleeping when the player is asleep:
    say ". . . You're sleeping."

Every turn:
    if The witching hour is happening:
instead of sleeping when the player is asleep: 
    say "Zzzz."

Every turn:
    if The witching hour is happening:
instead of waking up when the player is asleep: 
    now the player is awake; 
    say "You wake suddenly."

Every turn:
    if The witching hour is happening:
instead of doing something other than looking or sleeping when the player is awake: 
    say "You'd really rather just sleep. . ."

核心问题点

  • 规则层级违规:Inform7中Every turn仅用于注册每回合固定执行的逻辑块,不能在它的if条件分支内嵌套instead of操作拦截规则。这种写法会被编译器判定为无效语法,所有嵌套的拦截规则完全不会被引擎注册,等同于未编写,自然起不到条件判断的作用。
  • 场景触发冗余:Night场景同时绑定了3个触发入口(游戏开始、10PM、Dusk结束),会造成场景状态的异常跳变,但这不是睡眠功能失效的核心原因。
  • 规则条件缺失:所有睡眠相关的拦截规则没有绑定明确的前置判断,即便规则正常注册,也会出现不同状态下的逻辑冲突。

修复后的可运行代码

"Night Sleep Mechanism Test" by Scuttlebug.

! 基础环境与场景配置
The sun is a backdrop. It is everywhere. The description is "Currently out of sight."

! 昼夜循环场景(去掉冗余触发条件)
Night is a recurring scene. Night begins when Dusk ends. Night ends when the time of day is 1:30 AM.
When Night begins:
    say "The moon is up and the temperature drops abruptly to well below zero.";
    now the description of the sun is "Currently out of sight."

The witching hour is a recurring scene. The witching hour begins when Night ends. The witching hour ends when the time of day is 5:00 AM.
When The witching hour begins:
    say "You feel sleep calling you.";
    now the description of the sun is "Currently out of sight."

Day is a recurring scene. Day begins when The witching hour ends. Day ends when the time of day is 6:00 PM.
When Day begins:
    say "The sun is now properly up.";
    now the description of the sun is "A bright sun hangs high in the sky."

Dusk is a recurring scene. Dusk begins when Day ends. Dusk ends when the time of day is 10:00 PM.
When Dusk begins:
    say "The sun is setting.";
    now the description of the sun is "A faint orange glow dips below the horizon."

! 玩家状态定义
A person is either awake or asleep. A person is usually awake.

! 睡眠规则:直接将场景判断作为instead规则的触发条件,不嵌套在Every turn内
! 非允许睡眠时段,拦截睡眠操作
Instead of sleeping when The witching hour is not happening and player is awake:
    now the player is awake;
    say "You can't sleep now. . ."

! 允许睡眠时段,执行入睡逻辑
Instead of sleeping when The witching hour is happening and player is awake:
    now the player is asleep;
    say "You fall asleep. . ."

! 睡着状态下拦截非允许操作
Instead of doing something other than waking up, waiting or sleeping when The witching hour is happening and player is asleep:
    say ". . . You're sleeping."

! 睡着时重复输入睡眠的反馈
Instead of sleeping when The witching hour is happening and player is asleep:
    say "Zzzz."

! 醒来逻辑
Instead of waking up when The witching hour is happening and player is asleep:
    now the player is awake;
    say "You wake suddenly."

! 允许睡眠时段内醒着的操作引导
Instead of doing something other than looking or sleeping when The witching hour is happening and player is awake:
    say "You'd really rather just sleep. . ."

修复说明

  • 把原本嵌在Every turn块里的场景判断逻辑,直接移动到每一条instead of规则的触发条件从句中,符合Inform7的规则注册逻辑,让所有拦截判断真正生效。
  • 精简Night场景的触发入口,避免场景状态异常切换。
  • 给每一条操作规则补充了玩家状态的前置判断,消除不同状态下的规则冲突。
  • 补充了不同时段的太阳描述切换,让昼夜场景的反馈更连贯。

内容的提问来源于stack exchange,提问作者scuttlebug

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.15 08:45:05