I’m trying to write a rule to go through the player’s command word by word, comparing each word to some indexed texts, but I’m getting some error messages that confuse me – because they don’t really seem like they should be errors. Can someone explain what I’ve done wrong? My head is sort of spinning right now (you’ll be able to see why from my extraordinarily inelegant code), so any help would be appreciated.
Here are the messages:
(But if the uniquely matched block is a variable that holds a block, shouldn’t that work?)
(Again, what am I supposed to be passing to the phrase?)
(Number 1 is the one I want, but why don’t the instructions to work out indexed texts work there?)
I have a phrase beginning “To decide what indexed text is the apparent name of (cube - a block):” – is it that I shouldn’t use “To decide what indexed text is” phrases?
I’m hoping that the error messages themselves will give someone smarter an idea of what’s going on, but the whole convoluted code is below:
[spoiler][code]Use American dialect and the serial comma.
Section - Colors
[This is a bunch of stuff to make the color of a block vary dynamically depending on its real color and the color of the player’s glasses.]
A color is a kind of value. The colors are red, blue, and yellow.
A block is a kind of thing. A block has a color. A block has an indexed text called the known name. Understand “block” as a block.
Resetting the blocks is an activity.
For resetting the blocks:
repeat with cube running through blocks:
now the known name of the cube is the apparent name of the cube.
For printing the name of a block: say the known name of the item described.
When play begins:
carry out the resetting the blocks activity.
The player wears some glasses. The glasses have a color. The description of the glasses is “The glasses are currently colored [color of the glasses]. Push the button to change the color.” Understand “button” as the glasses.
Carry out pushing the glasses:
now the color of the glasses is the color after the color of the glasses;
carry out the resetting the blocks activity.
Report pushing the glasses:
say “The glasses are now colored [color of the glasses].”;
rule succeeds.
To decide what indexed text is the apparent name of (cube - a block):
if the player does not wear the glasses:
decide on “a [color of the cube] block”;
otherwise:
if the color of the glasses is red:
if the color of the cube is:
– red: decide on “a red block”;
– blue: decide on “a purple block”;
– yellow: decide on “an orange block”;
otherwise if the color of the glasses is blue:
if the color of the cube is:
– red: decide on “a purple block”;
– blue: decide on “a blue block”;
– yellow: decide on “a green block”;
otherwise: [the color of the glasses is yellow]
if the color of the cube is:
– red: decide on “an orange block”;
– blue: decide on “a green block”;
– yellow: decide on “a yellow block”.
Section - Replacing The Command With The Apparent Name
The uniquely matched block is a block that varies. [Just trying to see if this helps with the compiler error – it doesn’t.]
After reading a command:
let the hand-parsed command be indexed text;
now the hand-parsed command is the player’s command;
let the block matching list be a list of blocks;
let the first currently matched word number be a number; [we’re going to look for strings of words that all match a single block’s name]
repeat with n running from 1 to the number of punctuated words in the hand-parsed command: [punctuated words so we don’t get mixed up by commas and periods. Don’t use “yellow-green” as a color name.]
now the uniquely matched block is entry 1 in the block matching list;
if the number of entries in the block matching list is one:
if the apparent name of uniquely matched block does not match the text “[punctuated word number n in the hand-parsed command]”:
repeat with k running from the first currently matched word number to n minus one: [it’s the end of a string of words all matching one block, so replace it with its True Name, which I think had better be one word for this not to get fubar]
replace unpunctuated word number k in the hand-parsed command with “[the uniquely matched block]”;
now the block matching list is {}; [reset the list, but we have to see if this starts a new string]
repeat with tested block running through visible blocks:
if unpunctuated word number n in the hand-parsed command matches the text “[the apparent name of the tested block]”:
add the tested block to the block matching list;
now the first currently matched word number is n; [since we’ve started a new string]
if the number of entries in the block matching list is greater than one: [and thus has more than one entry]
repeat with tested block running through the block matching list:
if the apparent name of the tested block does not match the unpunctuated word number n in the hand-parsed command:
remove the tested block from the block matching list;
if the block matching list is empty: [uh-oh! that string of words is ambiguous]
repeat with k running from the first currently matched word number to n minus one:
replace unpunctuated word number k in the hand-parsed command with “block”; [replace everything in the string with “block”, which will be ambiguous]
now the block matching list is {}; [reset the list, but we have to see if this starts a new string]
repeat with tested block running through visible blocks:
if the apparent name of the tested block in the hand-parsed command matches the text the unpunctuated word number n in the hand-parsed command:
add the tested block to the block matching list;
now the first currently matched word number is n; [since we’ve started a new string]
if the block matching list is empty: [we need to start a new string]
repeat with tested block running through visible blocks:
if the apparent name of the tested block matches the text “[unpunctuated word number n in the hand-parsed command]”:
add the tested block to the block matching list;
now the first currently matched word number is n; [since we’ve started a new string]
say “Parsed command: [hand-parsed command].”; [debugging]
change the text of the player’s command to the hand-parsed command.
Section - Scenario
The Playroom is a room. Block1 is a red block in The Playroom. Block2 is a blue block in The Playroom. Block3 is a yellow block in The Playroom.
[/code][/spoiler]