Saying things in a table one at a time in order

I am finally learning tables. Gah. All the examples are far more complicated than what I want, and I just can’t extrapolate something simple from them. I want a single line from the table to be printed every turn in a given scenario, in order starting with A, then the next turn B, then C, then D and then starting again with A.

Every turn when the player is hinted:
	if the location is not inside:
		list the hintlines.
			
To list the hintlines:
	repeat through the Table of ThingsToSay:
		say "You hear someone say[paragraph break][lines entry][paragraph break]".

Table of ThingsToSay 
lines
"Line A'" 
"Line B" 
"Line C" 
"Line D"

This code is what I could find, but it lists every line every turn. I made it work randomly, but the random line picker tends to repeat one line several times before moving on, so I just want them in order, one every turn. Help?

If they weren’t that long and there weren’t that many, it would be more easily handled with adaptive text using cycling… but I assume they’re too long and plentiful for that to be tractable.

With tables, you’ll want an index column and a variable tracking where you are.

Table of ThingsToSay
line-idx    line
1    "Line A"
2    "Line B"

hintline-index is initially 1.

Every turn when the player is hinted and the location is not inside:
 say the line corresponding to a line-idx of hintline-index in the Table of ThingsToSay;
 if hintline-index is the number of rows in the Table of ThingsToSay, now hintline-index is 1;
 else increment hintline-index;

But if you only have one column, it can be easier to use a list, which is automatically accessible by an index…

hintline-index is initially 1.
hintlines is always { "LineA", "LineB", "..." }.

Every turn when the player is hinted and the location is not inside:
 say entry hintline-index of  hintlines;
  if hintline-index is the number of entries in hintlines, now hintline-index is 1;
  else increment hintline-index;

Edited to add:

You don’t need an index column for the table. You can just use this: [ I had made this edit immediately before I saw Nathanaël saying the same thing! ]

choose row hintline-index from the Table of ThingsToSay;
say line entry;

to get the line.

1 Like

It’s possible to skip the index column entirely (and it might be faster, although the difference of speed, if any, should be negligible for small table).

Every turn when the player is hinted and the location is not inside:
    choose row hintline-index in the Table of ThingsToSay
    say line entry;
    if hintline-index is the number of rows in the Table of ThingsToSay, now hintline-index is 1;
    else increment hintline-index;

EDIT: Well, you edited your message while I was writing. :grinning_face_with_smiling_eyes:

1 Like

Thanks, y’all. Tables are not easy for me, and the documentation examples seem very complicated. There may be easier ways to do this, but I am resolved on learning tables now, and this is a good opportunity. Hence I shall use tables everywhere whether they’re needed or not until I figure them out.

3 Likes

I feel like Tables are the probably the main area in Inform 7 where, if you don’t have a background in programming concepts (creating loops, indexed data, reading data) you’ll experience them as unnecessarily painful at first. And my personal spin on that is that in turn, I think THAT is because tables are the only bit of Inform 7 where I actually experience the English language layer as a bit of a verbose pain.

But overall, I still regard the English language aspect as mostly beyond criticism. I mean I love programming this way, and I’m someone who has programmed in 8-bit assembly, and therefore I am a Big Man whose opinions on this must be received with awe. If tables hurt in this scheme, I basically accept the hurt. (I didn’t feel comfortable until I made the wussy addition of ‘basically’.)

-Wade

That’s definitely my picture next to that description. Good to know that the difficulty with tables is more than just my incompetence.

It’s all been unnecessarily painful. I could have spent just a little time learning a single thing about computers instead of hollering for a teenager to come fix it every time my game wouldn’t play. And now I reap the whirlwind of my laziness.