I’m not sure if what I’m trying to do is even possible, but I’m trying to compare some text to that in a table and if they match, print one column and if they don’t, print the other. Here’s what I’ve got so far…
curRow is a number variable. curRow is usually 1.
SphinxLair is a room. The printed name of SphinxLair is "The Sphinx's Lair." The crystal box is a transparent closed container in SphinxLair. The lightbar is a lit thing in SphinxLair.
A lightsource is a kind of thing. A lightsource can be blue, red, or yellow (this is the color property). The flashlight is a lightsource. The color of flashlight is blue. Flashlight is in SphinxLair.
To say the colortext of flashlight:
if flashlight is blue:
say "blue";
if flashlight is red:
say "red";
if flashlight is yellow:
say "yellow";
Every turn:
if curRow is less than 3:
increase curRow by 1;
else:
now curRow is 1;
choose row curRow in the Table of Lightbar Colors;
if flashlightcolor entry is colortext of flashlight:
say "[rightColorResponse entry]";
otherwise:
say "[wrongColorTextResponse entry]";
Table of Lightbar Colors
lbcolor flashlightcolor wrongColorTextResponse rightColorResponse
"red" "blue" "The hideous color is horrifying.." "You can make out the faint writing on the walls"
"yellow" "red" "More vomit. Who made this room?" "You cannot believe your eyes."
"green" "yellow" "The vomit is even different now." "Something is very definitely on the walls here."
And the error I’m getting is:
In the sentence ‘if flashlightcolor entry is colortext of flashlight’ , I was expecting to read a condition, but instead found some text that I couldn’t understand - ‘flashlightcolor entry is colortext of flashlight’.
I was trying to match this phrase:
if (flashlightcolor entry is colortext of flashlight - a condition):
But I didn’t recognise ‘flashlightcolor entry is colortext of flashlight’.
Well, I could be wrong (It happens very often, I’m a beginner) but it seems to me that “colortext” is not a property of the flashlight item (unlike “color” in your code). In fact, it’s not even an object, just a part of a sentence name " To say the colortext of flashlight:". So I am not sure that “colortext of flashlight” does mean anything for the compiler.
Maybe you should rely on the “color” property when querying the table?
curRow is a number variable. curRow is usually 1.
SphinxLair is a room. The printed name of SphinxLair is "The Sphinx's Lair." The crystal box is a transparent closed container in SphinxLair. The lightbar is a lit thing in SphinxLair.
A lightsource is a kind of thing.
Color is a kind of value.
The colors are blue, red and yellow.
A lightsource has a color. The flashlight is a lightsource. The color of flashlight is blue. Flashlight is in SphinxLair.
To say the colortext of flashlight:
if flashlight is blue:
say "blue";
if flashlight is red:
say "red";
if flashlight is yellow:
say "yellow";
Every turn:
if curRow is less than 3:
increase curRow by 1;
else:
now curRow is 1;
choose row curRow in the Table of Lightbar Colors;
if color entry is color of flashlight:
say "[rightColorResponse entry]";
otherwise:
say "[wrongColorTextResponse entry]";
Table of Lightbar Colors
lbcolor color wrongColorTextResponse rightColorResponse
"red" blue "The hideous color is horrifying.." "You can make out the faint writing on the walls"
"yellow" red "More vomit. Who made this room?" "You cannot believe your eyes."
"green" yellow "The vomit is even different now." "Something is very definitely on the walls here."
Welcome
An Interactive Fiction
Release 1 / Serial number 240828 / Inform 7 v10.1.2 / D
The Sphinx's Lair.
You can see a crystal box (closed and empty), a lightbar and a flashlight here.
>wait
Time passes.
More vomit. Who made this room?
>wait
Time passes.
The vomit is even different now.
>wait
Time passes.
You can make out the faint writing on the walls
>
And finally, if you want really deal with texts while comparing table entries:
curRow is a number variable. curRow is usually 1.
SphinxLair is a room. The printed name of SphinxLair is "The Sphinx's Lair." The crystal box is a transparent closed container in SphinxLair. The lightbar is a lit thing in SphinxLair.
A lightsource is a kind of thing.
[The colors are blue, red and yellow.]
A lightsource has a text called color. The flashlight is a lightsource. The color of flashlight is "blue". Flashlight is in SphinxLair.
[To say the colortext of flashlight:
if flashlight is blue:
say "blue";
if flashlight is red:
say "red";
if flashlight is yellow:
say "yellow";]
Every turn:
if curRow is less than 3:
increase curRow by 1;
else:
now curRow is 1;
choose row curRow in the Table of Lightbar Colors;
if color entry is color of flashlight:
say "[rightColorResponse entry]";
otherwise:
say "[wrongColorTextResponse entry]";
Table of Lightbar Colors
lbcolor color wrongColorTextResponse rightColorResponse
"red" "blue" "The hideous color is horrifying.." "You can make out the faint writing on the walls"
"yellow" "red" "More vomit. Who made this room?" "You cannot believe your eyes."
"green" "yellow" "The vomit is even different now." "Something is very definitely on the walls here."
Instead of using a say phrase, use a decide phrase:
To decide what text is the colortext of flashlight:
if flashlight is blue:
decide on "blue";
if flashlight is red:
decide on "red";
if flashlight is yellow:
decide on "yellow";
This is like a function that returns a value, whereas a say phrase just prints to the screen.
Thank you Stéphane. I did initially try to just add the color values to the table but the compiler didn’t like it. For some reason it worked when you created a color kind and put the values in the table. If anyone here could explain why that works while declaring the colors as a property didn’t work, I’d like to understand better. I feel like this info is probably in the documentation but I wasn’t able to grasp it.
The simple answer is: when you write “A lightsource can be blue, red, or yellow” then you’re using a shortcut. Shortcuts are missing some functionality.
The more detailed (but still simplified) answer is that you’re defining some values that are only meaningful in the context of one property. They don’t exist as a separate kind, so a table can’t have a column of that kind.
Unless you specify the kind of a column, inform will try to infer the kind. When defining red, blue, and yellow as properties of a kind or object, it’s impossible for the compiler to infer what property you’re referring to, in general. A lightsource could have the red property, but so could a can of paint. How can the compiler tell which you mean when you write “red”?