交互式小说中随机查阅书籍主题的代码报错问题求助
问题解决:Inform7中随机翻阅书籍表的运行时错误
核心问题分析
你遇到的your former self是Inform7运行时的误导性报错文本,实际问题是错误地将table name属性当作实际表来操作。table name只是存储了表的标识符,并非表本身,直接对它调用表相关操作(比如number of rows)会触发属性访问错误。
修正方案
要通过table name属性访问实际表,必须使用the table of [表名属性]的语法,将属性中存储的表标识符转换为可操作的表对象。同时建议避免用contents作为自定义属性名(虽然你已经改了ToC,但这个习惯能减少内置属性冲突)。
完整修正代码
- 定义书的类型和表名属性:
A book is a kind of thing. A book has a table name called ToC.
- 定义书籍对应的内容表(以《Costa Rican Ornithology》为例):
Table of Costa Rican Birds Topic Reply "quetzal" "Resplendent quetzals are famous for their iridescent green tail feathers, and are considered a symbol of Costa Rica's biodiversity." "toucan" "Keel-billed toucans use their large, colorful bills to reach fruit on thin branches, and their bills are surprisingly light due to a honeycomb structure." "hummingbird" "Rufous-tailed hummingbirds are common in lowland forests, feeding on nectar and small insects. They can beat their wings up to 80 times per second."
- 给具体书籍绑定对应表:
The Costa Rican Ornithology is a book in the Library. The ToC of Costa Rican Ornithology is the Table of Costa Rican Birds.
- 修正随机翻阅的动作逻辑:
Understand "consult [a book]" as consulting vaguely. Consulting vaguely is an action applying to one visible thing. Carry out consulting vaguely: let target-book be the noun; let target-table be the table of ToC of target-book; choose a random row in target-table; say "[reply entry][paragraph break]".
额外说明
如果你想保留分步计算行数和随机行的逻辑,也可以改成:
Carry out consulting vaguely: let target-book be the noun; let target-table be the table of ToC of target-book; let row-count be the number of rows in target-table; let random-row-number be a random number from 1 to row-count; choose row random-row-number in target-table; say "[reply entry][paragraph break]".
关键是必须通过the table of ToC of target-book获取实际的表对象,而不是直接使用ToC of target-book。
内容的提问来源于stack exchange,提问作者John C
相关产品推荐
相关产品推荐

