You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Inform7中如何实现两台相机各自绑定独立胶卷的拍摄功能

Inform7 多相机绑定独立胶卷实现

问题背景

初始参考单相机示例实现的拍照逻辑代码如下,仅支持单台相机搭配全局唯一胶卷的逻辑,无法满足多相机独立胶卷的需求:

A photograph is a kind of thing. 36 photographs are in the film roll.

Appearance relates one thing to various photographs. The verb to be shown by means the appearance relation.

The description of a photograph is usually "It shows [a random thing which is shown by the item described]."

Understand "of [something related by reversed appearance]" as a photograph.

This allows the player to refer to any photograph by its subject: useful if we have a large number of them.

Now we create an action to let the player use the camera and generate these photograph objects:

The player carries a cheap instant camera.

Understand "photograph [something] with [camera]" as photographing. Understand "photograph [something] with [something preferably held]" as photographing. Photographing is an action applying to one visible thing and one carried thing, requiring light.

The photographing action has an object called the selected film.

Setting action variables for photographing:
    let N be a random photograph in the film roll;
    now the selected film is N.

Check photographing:
    if the second noun is not the camera, say "You need a camera for that purpose." instead.

Check photographing:
    if the noun is the camera, say "Sadly impossible." instead.

Check photographing:
    if the selected film is nothing, say "You're out of film." instead.

Carry out photographing:
    now the noun is shown by the selected film;
    move the selected film to the player.

Report photographing:
    say "Your camera instantly spits out [a selected film]."

需求为实现两台独立相机,每台绑定专属胶卷:使用1号相机拍摄的照片存储至1号胶卷,使用2号相机拍摄的照片存储至2号胶卷,两个胶卷的余量、存储内容完全独立互不干扰。

实现方案

核心调整是移除全局唯一的胶卷定义,将胶卷作为相机的绑定属性,每台相机初始化时自动生成专属胶卷和对应容量的空白底片,拍摄时从当前使用相机的专属胶卷中取用底片即可。

关键修改点

  • 定义film roll(胶卷)为容器类,给camera(相机)类新增绑定胶卷属性
  • 新增相机初始化规则,每台相机创建时自动在自身绑定胶卷中填充36张空白照片
  • 调整拍摄动作的选片逻辑,从当前手持相机的绑定胶卷中选取空白底片,不再读取全局胶卷
  • 微调动作检查规则,适配相机类判断,报错信息对应到当前使用的相机
  • 实例化两台独立相机,可根据需求放置在玩家背包或场景任意位置

修改后的完整可运行代码:

! 基础物件类型定义
A photograph is a kind of thing.
A film roll is a kind of container.
A camera is a kind of thing. A camera has a film roll called attached film.

! 相机初始化时自动填充36张空白底片到专属胶卷
When a camera is created:
    repeat with count running from 1 to 36:
        let new-photo be a photograph;
        now new-photo is in the attached film of the item described.

! 原有照片关联、识别逻辑保留
Appearance relates one thing to various photographs. The verb to be shown by means the appearance relation.
The description of a photograph is usually "It shows [a random thing which is shown by the item described]."
Understand "of [something related by reversed appearance]" as a photograph.

! 场景与相机实例初始化
The Lab is a room. The player is in the Lab.
The player carries a cheap instant camera (called camera 1).
A premium instant camera (called camera 2) is on the lab table in the Lab.

! 拍照动作定义
Understand "photograph [something] with [camera]" as photographing.
Understand "photograph [something] with [something preferably held]" as photographing.
Photographing is an action applying to one visible thing and one carried thing, requiring light.
The photographing action has an object called the selected film.

! 从当前使用相机的专属胶卷选空白底片
Setting action variables for photographing:
    let active-camera be the second noun;
    let N be a random photograph in the attached film of active-camera;
    now the selected film is N.

! 动作检查规则
Check photographing:
    if the second noun is not a camera, say "You need a camera for that purpose." instead.
Check photographing:
    if the noun is the second noun, say "You can't photograph a camera with itself." instead.
Check photographing:
    if the selected film is nothing, say "The camera you're using is out of film." instead.

! 动作执行与报告
Carry out photographing:
    now the noun is shown by the selected film;
    move the selected film to the player.
Report photographing:
    say "Your camera instantly spits out [a selected film]."

实现效果

  • 两台相机的胶卷容量完全独立,单台相机拍完36张胶卷不会影响另一台的剩余可拍数量
  • 拍摄时自动匹配当前手持相机的胶卷出片,不会出现跨相机占用胶卷的问题
  • 后续需要新增更多相机时,只需创建camera类的实例即可,无需重复编写胶卷初始化逻辑
  • 原有按拍摄主体识别照片的功能完全保留,不受多相机逻辑调整影响

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.30 17:15:45