Once more, I return hat in hand for help

Hi, all!

I try to figure things out on my own but am having trouble – still learning but still learning, unfortunately.

What I want to do is look up in a table the row that corresponds to a variable.

One table looks like this:

Table of Elevated Telescope Descriptions
grid (a number) UA UB Description
1 “unicode Greek small letter pi” “unicode comet” “Cepheus”

The value in grid is arrived at by moving the telescope around via joystick – imagine a grid in which the player moves the view around to different descriptions.

I have the mechanism correct in changing the “location” of the view, for example:

check pushing down:
if powerbutton is switched off:
say “Nothing happens.” instead;
if noun is not joystick:
say “I don’t understand what you want me to push.” instead;
if totalgridvalue > 39:
say “The machine buzzes.” instead;
otherwise:
increase totalgridvalue by 10;
say “The machine issues a pleasant ping and the picture on the screen changes.”;
continue the action.

This works, totalgridvalue changes in the manner and value that it should. What I want to do is look up the row in the table that corresponds to the value of totalgridvalue.

Hopefully this makes sense. Thank you for your help!

I think you want to read the section of WWI on “Choosing Rows” in the chapter about “Tables”. The syntax there should let you pick a row based on the value of your variable. There is also a shortcut using the idea of a “corresponding entry” if you only want a paired value from th row instead of selecting the whole row.

FYI, the structure of your rule looks a little tangled. I think you might be better off breaking it into several more specific rules. Also, some of the logic (for successful actions) might be better moved to other rulebooks like carry out, report, or after. Check the chapters on action processing for more details.

Thank you! I don’t doubt there are better or more-efficient ways to do things and I appreciate the guidance.

For example, you might organize the rule like this:

[code]Check pushing down when the powerbutton is switched off:
say “Nothing happens.” instead.

Check pushing down when the noun is not the joystick:
say “I don’t understand what you want me to push.” instead.

Carry out pushing down:
if total gridvalue <= 39, increase totalgridvalue by 10.

After pushing down when totalgridvalue > 39:
say “The machine buzzes.”

Report pushing down:
say “The machine issues a pleasant ping and the picture on the screen changes.”[/code]

Note that, with the exception of the check rules, you don’t have to explicitly tell the action to stop or continue. Carry out, and report rules automatically continue unless otherwise noted; after rules automatically stop unless otherwise noted.

Also, consider using code tags when you post code. It will preserve your code’s indentation and make it much easier to read.

Just type:

[code]
Your code goes here
[/code]

Can you answer this, for my own knowledge – is approaching it in this manner preferable because of processing time (speed) or memory usage, or will it just overall function better by using this coding instead? Hopefully that makes sense.

A follow-up question, then (having changed the coding of commands similar to the above, so that I am ruling out error):

I have the table row being looked up but returning the wrong value (instead from a different row). The easiest answer is that obviously it’s looking up the wrong row, however:

Take the following syntax:

say “The picture is [description in row totalgridvalue of the Table of Elevated Telescope Descriptions] [totalgridvalue]”;

I have the second [totalgridvalue] in there to help debug, this way I know that the game has the correct value. If I change the value of the variable by pushing the joystick down, this is returned:

“The machine issues a pleasant ping as the picture changes. 11”

And the value should be 11. When I ask the game to report the description of that row in the table, it then returns:

“THis is a picture of Aquarius. 11” which is the correct totalgridvalue. However, this is the description from row 21.

Similarly, if I ask for a description when the totalgridvalue is 21, it then returns:

“This is a picture of Aries. 21” However, this is the description from row 41.

To me, this suggests that something is causing a routine to run twice. However, I cannot find the error.

Any suggestions greatly appreciated.

I can’t speak for Mike, but my take is that it’s more about code structure, simplicity, and the possibility of reuse.

Reality isn’t always as clean as the theory, but the idea is that check, carry out, and report rules define the default behavior of an action. Check tests the preconditions that must be true before the action can logically take place. Carry out performs the action itself by modifying the world model. Report produces output that notifies the player about what’s happened. In theory, one could grab those rules and transplant the action into a different game.

Before, after, and instead rules are used to describe exceptions to this general behavior for specific objects and situations.

So, e…g, if we wanted to prevent an actor from dropping an object that they’re not holding, that’s a general constraint on dropping, so we’d make it a check rule (if it didn’t already exist in the standard rules). If instead, we wanted to prevent a player from dropping a candy apple that they’ve picked up because it’s too sticky, that’s a candidate for a before or instead rule, because it has nothing to do with dropping in general but rather has to do with an exception concerning a specific object.

Now, if we changed our world model so that all things can be sticky or not sticky, then it might make sense to add a check rule for dropping sticky things.

See §12.21. (Guidelines on how to write rules about actions) for more about which kinds of rules to write in different situations.

Your best bet to get help with a specific problem like this is to pare down your program into a small test program that still exhibits the error and post that.

Taking a shot in the dark here:
Are you saying “choose row [number] in the table”, when your table is sparse (some numbers don’t appear in it)? The “choose row [number]” phrase takes the Nth row from the top, regardless of what value is in the first column. “Choose the row with a [column] of [value]” is better in that case.

Yes, you’re correct that is the problem, I thought of it while driving to work. Thank you, however!

Thank you for this! The answers may be obvious to some, but the way I learn is by understanding the why. This was better than any description I’ve read in the included manual, the PDF, and the book that I purchase on Inform. Which sucks by the way, there are like two pages in the entire book on tables.

I think that I still suffer from old programmer’s syndrome, if it exists – what exists in my head is a vestige of how I learned to code, back with BASIC. The multiple ways to accomplish the same goal can be a little weird.

Anyway, thank you for your help!