A (simple?) question about tables and variables

Is there a way to read some text into a variable from a table without using indexed text? Or from a list? Sorry if this is basic, I’m just looking at the documentation and for whatever reason not able to come up with something that works.

Using this table from the documentation, for example:

Table 2.1 - Selected Elements
Element Symbol Atomic number Atomic weight
“Hydrogen” “H” 1 1
“Iron” “Fe” 26 56
“Zinc” “Zn” 30 65
“Uranium” “U” 92 238

… I can select a row or repeat through the table and SAY the names of elements, but I can’t seem to use the same logic to change a text variable to the name of an element in order to do anything more exciting with it, or otherwise use it later. What am I missing?

Have a look at this example I wrote. The parlance you want is ‘now (text variable) is (such-and-such) entry’, where such-and-such is the title of a column in the table.

In the test program, ‘choice’ is the text variable. Each time you type ‘yo’, the game first picks a random row from the table and sets choice to that row’s Element entry. It then prints the contents of choice.

Then it picks the row with an atomic number of 1 (which is always the Hydrogen row), and sets choice to that row’s Element Entry - which will always be Hydrogen. But it’s printing the contents of choice to prove that it worked this out by passing the value through the text variable.

When I use the parlance ‘now choice is Element entry’, it’s best to do that within a few lines of code of choosing the row so that there’s no confusion about which row the game chose. As it says in 15.5 of the Inform docs: “This notation can only be used if a “choose” has certainly already happened, and it is a good idea to make that choice somewhere close by in the source code (and certainly in the same rule or phrase definition) for the sake of avoiding errors.”

[code]“Table example”

Test lab is a room.

Table 2.1 - Selected Elements
Element Symbol Atomic number Atomic weight
“Hydrogen” “H” 1 1
“Iron” “Fe” 26 56
“Zinc” “Zn” 30 65
“Uranium” “U” 92 238

choice is a text variable.

When play begins:
say “TYPE ‘YO’ TO RUN THE TEST.”;

Understand “yo” as wanting to run the test.

wanting to run the test is an action applying to nothing.

Carry out wanting to run the test:
choose a random row in Table 2.1;
now choice is Element entry;
say “1st randomised value of Choice is [choice].”;
choose a row with an Atomic Number of 1 in Table 2.1;
now choice is Element entry;
say “Choice then set to [choice] - which should be Hydrogen.”[/code]

  • Wade

Thank you so much. I believe I had tried that particular phrasing and ruled it out an option because I didn’t have it near enough to the line for picking a row, as you suggested. I have it working now, much frustration saved!

Hello everyone,

hijacking this thread seem more appropriate than opening another one as its similar to my problem.
i hope someone could help.

I spent hours digging through cookbook trying to code a behavior and all i got is fistful of hair.

Here is what i am trying to achieve (not an actual text, explaining purposes only):

Table of whispers
“You hear a voice: Hey, player…
“You hear the voice again: …take that gun and…
“Voice is booming through your head: …KILL HIM!

i want game to display messages in normal order, after every and any action player may perform.

ive managed this with on every turn: but only could take random table entry to show (as seen in uptown girls)
i also tried with to list the but only could achieve it by replacing and typing specific command (as seen in recent monarchs) which i do not want.

i could use above “table example” but it has both random pick and replacing specific command to do so :frowning:

i will probably want to stop this if the player meets certain criteria (killing subject without waiting suggestion, leaving room)

for me, it seems like you have to write completely different kind of code for two very similar things. i am utterly confused with inform.

i hope im not asking too much, but i depleted all my good will and energy trying to code something simple as this.

thank you

Room
You are in the room.

>any action

You hear a voice: Hey, player...

Room
You are in the room.

>any action

You hear the voice again: ...take that gun and...

Room
You are in the room.

>any action

Voice is booming through your head: ...KILL HIM!

Room
You are in the room.

>any action

Voice is booming through your head: ...KILL HIM!

If what you want is really just to say a new thing at the end of every turn, this is the easier way to do it:

Every turn: say "[one of]You hear a voice: Hey, player...[or]You hear the voice again: ...take that gun and...[or]Voice is booming through your head: ...KILL HIM![stopping]"

But here’s a way to do it with tables, if what you actually want is doing something more complicated than just saying things.

[code]
Table of Whispers
whisper
“You hear a voice: Hey, player…”
“You hear the voice again: …take that gun and…”
“Voice is booming through your head: …KILL HIM!”

Every turn:
repeat through the Table of Whispers:
say whisper entry;
if the number of filled rows in the Table of Whispers is greater than 1, blank out the whole row;
rule succeeds.
[/code](The reason you have to set up a loop and break out of it, rather than just choose row 1 each time and erase it, I suppose, is that, after a row has been blanked out, it’s still there and counts, it just holds no data.)

And (as usual) you can make the every turn rule conditional with a when-clause:

Every turn when the location is the place and we have not taken inventory and the arch-enemy is not dead: say [etc.]"

thanks felix,

i made a mistake by believing i can make miracles in the first week of using inform.
its just a language like any other and you have to learn proper syntax.

i do intend to use the tables to make more complicated things. i just needed simple version of the feature to see how the basics work.

ill keep it small for now and work on simple things until im comfortable with syntax.

and thanks again, these examples are explaining exactly what i needed.

i love digging through alien code for bits and pieces to make my own code work but sometimes, when you hit the wall, straightforward solution is much appreciated

If so, the extension presented in this thread <[url]https://intfiction.org/t/yet-another-i7-extension-event-chains/4542/1]> might be useful.

now this is what i had in mind exactly!

this can be used for all kind of notifications under certain conditions.

background npc talk, narration, sounds, smells, radio playing, you name it.
all neatly organized in table and easy to implement.
and order is important because i sometimes want to display larger text, line after line, turn after turn.

this will help a bunch

thanks