Run-time problem P22

Hey, surprise surprise, it’s me again!

[code]Every turn when a giant fly is in the location:
if a random chance of 1 in 3 succeeds, choose a random row in the Table of Giant Fly Activity;
say “[comment entry]”.

Table of Giant Fly Activity
comment
“The giant fly makes enormous buzzing noises”
“The giant fly buzzes enormously”
“The enormous fly makes a giant buzz”[/code]

This works once. “z”-ing a second time in the location where the giant fly is gives me “*** Run-time problem P22: Attempt to look up a non-existent row in the table ‘** No such table **’”. To nobody’s amazement, this scares and confuses me. What am I doing wrong? (The comments are just placeholders for the moment, and I haven’t been having any issues with random tables anywhere else)

The problem is that the structure of your every turn rule requires the say “[comment entry]” line to fire every turn, regardless of whether a row was chosen (which happens only 1 in 3 times). The run-time error occurs when you hit that line without having chosen a row. You need to put the table code together in a block, like this:

Every turn when a giant fly is in the location: if a random chance of 1 in 3 succeeds: choose a random row in the Table of Giant Fly Activity; say "[comment entry]".

Now a row will always have been chosen before you try to use row data.

–Erik

Although it doesn’t look like it, I’d say this is a colon and indentation error. The instruction to pick a row on a one-in-three random chance is one statement; the instruction to always print the desired row is another, separate statement. This means that there’s a 2/3 likelihood of no row being specified as you ask for it to be printed, causing Inform to go “huh?”

Every turn when a giant fly is in the location: if a random chance of 1 in 3 succeeds: choose a random row in the Table of Giant Fly Activity; say "[comment entry]".

This should fix the issue.

EDIT: And of course Erik beat me to it with a more succinct answer.

Once again the expertise of this most excellent of forums has rescued me. Thank you very much.