CYOA Extension needs help/input

Mostly at the urging of Hanon Ondricek, I’m going to make a public version of the CYOA extension I made, inspired by the Adventure Book extension by Edward Griffiths. It’s distinctive in that it can freely switch between CYOA modes and the interactive parser. It also does away with choice objects altogether and provides a lot more flexibility when writing. It could be considered an “Advanced” Adventure Book.

It worked perfectly before the new version of I7. However, it has hit a couple of snafus. I fixed a couple, but there’s one that still irks me. Namely, the relations that control pages (the page-dependency and page-cancellation relations) do not work. If you run the code you’ll find that page6 doesn’t cancel page8 and page9 doesn’t require page7. I was wondering if anyone had any insight on that.

Also, if anyone has any feature requests, I’d be glad to hear them.

Code here.

[spoiler][code]“CYOA Hybrid” by Another Wannabe

Part - CYOA Mode

The CYOA mode is a truth state that varies.

To decide if in CYOA mode:
if CYOA mode is true:
decide yes;
decide no.
To decide if not in CYOA mode:
if CYOA mode is true:
decide no;
decide yes.

To execute page turning:
let passed pages be a list of pages;
let finish condition be a truth state;
[if the description of X is not “”:
say the description of X;
say paragraph break;]
while the finish condition is false:
follow the page-switch rules for the current page;
[if a page relates to the current page by the page-flipping relation:]
if the current page flips to a page (called p1):
add the current page to the passed pages;
unless the current page is a one-off and the current page is previously displayed:
if in cyoa debug mode:
say “[bracket]Working through [current page] to [destination page]…[close bracket]”;
if the description of the current page is not “”:
say the description of the current page;
say paragraph break;
follow the page-output rules for the current page;
follow the page-toggle rules for the current page;
now the displayed boolean of the current page is true;
else if in cyoa debug mode:
say “[bracket]Skipping past [current page]…[close bracket]”;
now the current page is p1;
if the current page is listed in the passed pages:
if in cyoa debug mode:
say “[bracket]It appears that you may have accidently created an infinite loop by following a previous page. I am now failsafing to the previous page.[close bracket]”;
now the current page is the previous page;
break;
else:
now the finish condition is true;
now the displayed boolean of the current page is true;
if in cyoa debug mode:
say “[bracket]Working through [current page]…[close bracket]”;
follow the page-toggle rules for the current page;
if the current page is a dead-end:
if the description of the current page is not “”:
say the description of the current page;
say paragraph break;
follow the page-output rules for the current page;
now the current page is the previous page;
follow the page-toggle rules for the current page.

To turn to (x - a page):
now the previous page is the current page;
now the current page is X;
execute page turning;
try looking.

To switch to CYOA at (x - a page), without looking:
now the current page is X;
now CYOA mode is true;
set choice-window;
execute page turning;
unless without looking:
try looking.
To switch from CYOA:
now CYOA mode is false;
unset choice-window;
try looking.

Part - Pages and Choices

A page is a kind of object. The no-page is a page.
A page has a text called a description. A page has a truth state called the displayed boolean. A page has a text called a cdesc.

[A choice is a kind of value. The no-choice is a choice.
A choice has a text called a description. A choice has a truth state called chosen boolean. A choice has a truth state called displayed boolean.]

The current page is a page that varies.
The previous page is a page that varies.

Definition: a page is previously displayed if its displayed boolean is true.
[Definition: a choice is previously displayed if its displayed boolean is true.
Definition: a choice is previously chosen if its chosen boolean is true. ]

To decide whether reading (X - a page):
if X is the current page and in CYOA mode:
decide yes;
decide no.

Part - Showing Choices

Table of Currently Available Choices
index decision
(number) (page)
with 32 blank rows.

Page-turning relates various pages to various pages.
The verb to turn to (he turns to, they turn to, he turned to, it is turned to, it is turning to) implies the page-turning relation.
The verb to be for implies the reversed page-turning relation.

To clear choices:
blank out the whole of Table of Currently Available Choices.

Choice-displaying something is an activity on a page.

The assigned index is a number that varies.

[To say note dead-end for (X - a choice):
if in cyoa debug mode:
if the next page of X offers no choices or the next page of X passes to nothing:
say “**”.]

Before choice-displaying a page (called X) (this is the bookkeeping tasks whilst choice displaying rule):
increment the assigned index;
choose a blank row from the table of currently available choices;
now the index entry is the assigned index;
now the decision entry is X.

Before choice-displaying a page (this is the show choice number rule):
say "[assigned index]) ".

Rule for choice-displaying a page (called X) (this is the print choice description rule):
say “[cdesc of X][line break]”.

Displaying available decisions of something is an activity on pages.

Rule for displaying available decisions of a page (called N):
clear choices;
let F be a truth state;
if N turns to a page:
repeat with K running through pages turned to by N:
follow the choice-switch rules for K;
unless the rule failed:
carry out the choice-displaying activity with K;
if F is true:
say line break;
now the assigned index is 0.

Section - Suppressing Choices Depending on Conditions

The choice-switch rules is a page based rulebook.

Section - Toggling Conditions After Selecting a Choice

The page-switch rules are a page based rulebook.
The page-toggle rules are a page based rulebook.

Section - Displaying Complex Output

The page-output rules are a page based rulebook.

Chapter - Understanding Choices

Choosing is an action applying to a number.
Understand “[a number]” as choosing when in CYOA mode.

Check choosing (this is the can’t choose when not in CYOA mode rule):
if not in CYOA mode:
say “You don’t have a choice to make… you are playing in interactive mode.” instead.
Check choosing (this is the can’t choose whilst no choices are offered rule):
if the current page turns to no pages:
say “This page doesn’t offer any choices.” instead.
Check choosing (this is the can’t choose a number for a non-existant choice rule):
if the number understood is not an index listed in the table of currently available choices:
say “There is no choice corresponding to that number.” instead.

A page has an object called a cyoa teleport. The cyoa teleport is usually nowhere. A page can be no-look.

Carry out choosing (this is the standard carry out choosing rule):
let K be the decision corresponding to an index of number understood in the table of currently available choices;
carry out the selecting activity with K;
try looking;
if the current page is an end-page:
switch from cyoa.
[ if the cyoa teleport of the current page is a room and the current page is no-look:
move the player to the cyoa teleport of the current page, without printing a room description;
else if the cyoa teleport of the current page is a room:
move the player to the cyoa teleport of the current page.]

Chapter - Selecting Activity

[Page-turning relates various choices to a page (called the next page). The verb to turn to (he turns to, they turn to, he turned to, it is turned to, he is turning to) implies the page-turning relation.]

Page-flipping relates various pages to one page (called the destination page). The verb to flip to (he flips to, they flip to, he flipped to, it is flipped to, it is flipping to) implies the page-flipping relation.

A page can be an end-page.

Selecting something is an activity on pages.

Before selecting a page (called x) (this is the print choice selection rule):
say “[italic type][bracket][cdesc of X][close bracket][roman type][paragraph break]”.

Rule for selecting a page (called x) (this is the standard change pages rule):
now the previous page is the current page;
now the current page is X;
execute page turning.

Chapter - Refresh Pages

Carry out looking when in CYOA mode:
if in cyoa debug mode:
say “[bracket]Looking at [current page][close bracket]…”;
if the description of the current page is not “”:
say the description of the current page;
say paragraph break;
now the displayed boolean of the current page is true;
refresh choices;
rule succeeds.

Chapter - Page Options

Section - One-Off Pages

A page can be one-off.

A choice-switch rule for a one-off page (called F) (this is the don’t display choices turning to one-off pages again rule):
if F is previously displayed:
rule fails.

Section - Dead Ends

A page can be a dead-end.

Section - Item-Dependent

Item-dependency relates various pages to one thing (called the required item).
The verb to be item-dependent on implies the item-dependency relation.

Item-cancellation relates various pages to one thing (called the canceling item).
The verb to be item-canceled by implies the item-cancellation relation.

A choice-switch rule for a page (called Z) (this is the don’t display choices without the required item rule):
if Z is item-dependent on something:
if the required item of Z is not enclosed by the player:
rule fails.

A choice-switch rule for a page (called Z) (this is the don’t display choices with the canceling item rule):
if Z is item-canceled by something:
if canceling item of Z is enclosed by the player:
rule fails.

Section - Page-Dependent

Page-dependency relates various pages to various pages.
The verb to be page-dependent on implies the page-dependency relation.

Page-cancellation relates various pages to various pages.
The verb to be page-canceled by implies the page-cancellation relation.

A choice-switch rule for a page (called Z) (this is the don’t display choices without the required pages rule):
repeat with X running through pages which are page-dependent on Z:
if X is not previously displayed:
rule fails.

A choice-switch rule for a page (called Z) (this is the don’t display choices with a canceled page rule):
repeat with X running through pages which are page-canceled by Z:
if X is previously displayed:
rule fails.

[A page has a list of pages called the required pages. The required pages are usually {}.
A page can be requirement-intensive or requirement-lax. A page is usually requirement-intensive.

A page has a list of pages called the canceling pages. The canceling pages are usually {}.
A page can be canceling-intensive or canceling-lax. A page is usually canceling-lax.]

[A choice-switch rule for a page (called Z) (this is the don’t display choices without the required pages rule):
unless the required pages of Z is {}:
if Z is requirement-intensive:
repeat with X running through the required pages of Z:
if X is not previously displayed:
rule fails;
else if Z is requirement-lax:
let N be a truth state;
repeat with X running through the required pages of Z:
if X is previously displayed:
now N is true;
break;
if N is false:
rule fails.

A choice-switch rule for a page (called Z) (this is the don’t display choices with the canceling pages rule):
unless the canceling pages of Z is {}:
if Z is canceling-intensive:
let N be a truth state;
repeat with X running through the required pages of Z:
if X is not previously displayed:
now N is true;
break;
if N is false:
rule fails;
else if Z is canceling-lax:
repeat with X running through the required pages of Z:
if X is previously displayed:
rule fails.]

Section - Activating/Deactivating

[A page can be active or inactive. A page is usually active.

A choice-switch rule for a page (called Z) (this is the don’t display choices to inactive pages rule):
if Z is inactive, rule fails.

To activate (x - a page):
now x is active.
To deactivate (x - a page):
now x is inactive

To activate (x - a list of pages):
repeat with Y running through X:
now Y is active.
To deactivate (x - a list of pages):
repeat with Y running through X:
now Y is inactive.

Page-activation relates various pages to various pages.
Page-deactivation relates various pages to various pages.

The verb to

A page has a list of pages called the activated pages. The activated pages are usually {}.
A page has a list of pages called the deactivated pages. The deactivated pages are usually {}.

A page-toggle for a page (called X):
if the activated pages of X is not {}:
activate the activated pages of X;
if the deactivated pages of X is not {}:
deactivate the deactivated pages of X.]

Chapter - Item Invoking

Item-invoking disabled is a truth state that varies.

Item-invoking is an action applying to one visible thing. Understand “[a thing]” as item-invoking when in cyoa mode and item-invoking disabled is false.

Check item-invoking (this is the can’t use item-invoking mode outside of CYOA rule):
unless in cyoa mode:
say “You can’t use items like that outside of choice mode, you have to actually describe how you are going to use it.”

Report item-invoking (this is the block item-invoking rule):
say “[The noun] can’t be used here.”

Chapter - CYOA Teleport

To CYOA teleport to (Z - an object):
move player to Z, without printing a room description

Part - Cyoa Debug Mode

The CYOA debug boolean is a truth state that varies.

To decide if in cyoa debug mode:
if the CYOA debug boolean is true:
decide yes;
decide no.

Section - Toggling Debug Mode (not for release)

Toggling debug mode is an action out of world applying to nothing.

Understand “debug” as toggling debug mode.

Carry out toggling debug mode:
if CYOA debug boolean is false:
now CYOA debug boolean is true;
say “Debug mode now on.”;
else:
now CYOA debug boolean is false;
say “Debug mode now off.”

Part - Parser

The reading a command activity has a truth state called the command accepted.

The CYOA error message is a text variable. The CYOA error message is “That command isn’t available in choice mode.”

After reading a command when in cyoa mode:
if the player’s command matches “[a number]”, now the command accepted is true.

Last after reading a command when in cyoa mode:
if the command accepted is false:
say “[CYOA error message][paragraph break]”;
reject the player’s command;
else:
now the command accepted is true.

Chapter - Accept Testing Commands (not for release)

After reading a command when in CYOA mode (this is the accept testing commands during CYOA rule):
if the player’s command matches “debug”, now the command accepted is true;
if the player’s command includes “showme”, now the command accepted is true;
if the player’s command includes “rules”, now the command accepted is true;
if the player’s command includes “test”, now the command accepted is true.

Chapter - Accept System Commands

After reading a command when in cyoa mode (this is the accept system commands during CYOA rule):
if the player’s command matches “l/look/i/inventory/q/quit/save/restore/restart/g/undo”, now the command accepted is true.

Chapter - Accept Examining Commands

Use cyoa examining translates as (- Constant CYOA_EXAMINING; -).

After reading a command when in cyoa mode and the cyoa examining option is active (this is the accept examining rule):
if the player’s command includes “x/examine”, now the command accepted is true.

Chapter - Accept Item Commands

After reading a command when in cyoa mode (this is the accept items rule):
if the player’s command matches “[a thing]”, now the command accepted is true.

Part - Time

[The don’t pass time during CYOA mode rule is listed before the every turn stage rule in the turn sequence rules.
This is the don’t pass time during CYOA mode rule: if in CYOA mode, rule succeeds.]

First every turn when in cyoa mode (this is the prevent every turn events rule):
rule succeeds.

Part - Choice Window (for use with Flexible Windows by Jon Ingold)

The choice window size is a number that varies. The choice window size is 20.

The choice-window is a text-buffer g-window spawned by the main-window. The position is g-placebelow. The scale method of the choice-window is g-proportional. The measurement of the choice-window is 20.

When play begins (this is the set the choice-window size rule):
now the measurement of the choice-window is the choice window size.

Window-drawing rule for the choice-window (this is the construct choices rule):
move focus to choice-window, clearing the window;
carry out the displaying available decisions activity with the current page;
return to main screen.

To set choice-window:
open up choice-window.
To unset choice-window:
shut down choice-window.
To refresh choices:
follow the window-drawing rules for the choice-window;

Part - Windowless CYOA (for use without Flexible Windows by Jon Ingold)

To set choice-window:
do nothing.
To unset choice-window:
do nothing.
To refresh choices:
carry out the displaying available decisions activity with the current page.

Volume - Testing

The testing chamber is a room.

When play begins:
switch to cyoa at page1, without looking.

The banana is a thing carried by the player.

Page1 is a page.
“This is the first page.”

Page2 is a page. The cdesc is “This is a choice.”. It is for page1. It flips to page3.
“This is the second page.”

Page3 is a page.
“This is the third page.”

Page4 is a page. The cdesc is “This choice hates bananas.”. It is item-canceled by the banana. It is for page3.
“This is the fourth page.”

Page5 is a page. The cdesc is “This choice loves bananas.”. It is item-dependent on the banana. It is for page3.
“This is the fifth page.”

Page6 is a page. The cdesc is “This choice cancels the eighth page.” It is for page5.
“This is the sixth page.”

Page7 is a page. The cdesc is “This choice is required for the ninth page.” It is for page5.
“This is the seventh page.”

Page8 is a page. The cdesc is “This choice is canceled by page 6.” It is for page6, page7. It is page-canceled by page6.
“This is the eighth page.”

Page9 is a page. The cdesc is “This choice is required by page 7.” It is for page6, page7. It is page-dependent on page7.
“This is the ninth page.”[/code][/spoiler]

6L06 reverses some relations (mainly using the “relates to” syntax, I believe) that were incorrectly interpreted in 6G02. Try inverting your subject and object in the lines that define the variables, or in the logic relating to them, and see if that gets you anywhere.