Table Trouble: Order of doing things

Hey All–

So I hate tables, but I need one and it’s hurting my brain. I mean, I’ve read through all the Tables documentation, and I am just not smart enough to extrapolate any of that to a new situation.

Let’s say you try on four pairs of shoes, and you try them on in the order you want, and get information about how each one feels, and then you can ponder to recall this information so you can pick one. I haven’t been able to figure out much of anything about this from looking at examples. Like, should I do a completely blank table and fill it in as I go? Or should I just have the order of shoe tried blank and fill in the rest as I go? Can I have object names in a table? There have a been a few threads about that but they don’t say whether you should have them in a table and outside of a table, and whether they’ll actually function as objects when in the table they’re just text.

Maybe something like this make-believe code that just says what I want instead of anything Inform understands:

Table of ShoeOrder
OrderNumber	ShoeName	Memory
a number	flat	"Not much arch support."
a number	boot	"Very pointy toes."
a number	sandal	"Very thin sole.".
a number	sneaker	"Doesn't breathe well.".


A shoe is a kind of thing.
The sandal is here. It is a shoe. The description is "So cute!".
The sneaker is here. It is a shoe. The description is "So colorful!".
The boot is here. It is a shoe. The description is "So chic!".
The flat is here. It is a shoe.The description is "So elegant!".

WearOrder is a number that varies. WearOrder is initially 0.

Instead of wearing a shoe:
	if the noun is worn:
		say "You already tried it on!";
	otherwise:
		say "You put [the noun] on your foot and frown, because [memory corresponding to the noun in the Table of ShoeOrder]";
		now the noun is worn;
        increment WearOrder
		now ordernumber corresponding to the noun is WearOrder.
		
Understand the command "ponder" as something new. Understand "ponder" as pondering. Pondering is an action applying to nothing.

Carry out pondering:
    repeat through Table of ShoeOrder;
    sort the table of Shoe in reverse OrderNumber order;
	showme contents of Table of ShoeOrder, minus any shoes we haven't tried on yet.

It is actually really important that this record the order that the player tried the shoes.

1 Like

I cleaned up a bit and I think it does what you want. Pretty much what you had.

Table of ShoeOrder
OrderNumber	ShoeName	Memory
0	flat	"Not much arch support"
0	boot	"Very pointy toes"
0	sandal	"Very thin sole"
0	sneaker	"Doesn't breathe well"

The lab is a room.



A shoe is a kind of thing. A shoe can be worn. 
The sandal is in the lab. It is a shoe. The description is "So cute!".
The sneaker is in the lab. It is a shoe. The description is "So colorful!".
The boot is in the lab. It is a shoe. The description is "So chic!".
The flat is in the lab. It is a shoe.The description is "So elegant!".

WearOrder is a number that varies. WearOrder is initially 0.

Instead of wearing a shoe:
	if the noun is worn:
		say "You already tried it on!";
	otherwise:
		choose the row with ShoeName of the noun in Table of ShoeOrder;
		say "You put [the noun] on your foot and frown, because [memory entry].";
		now the noun is worn;
		increment WearOrder;
		now ordernumber entry is WearOrder;
		showme the contents of Table of ShoeOrder;
		
		
Pondering is an action applying to nothing. Understand "ponder" as pondering. 

Carry out pondering:
	sort the table of Shoeorder in reverse OrderNumber order;
	repeat through Table of ShoeOrder:
		if ordernumber entry is not 0:
			say "[ordernumber entry]: [shoename entry] -- [memory entry]."
3 Likes

Wow, I got fairly close. Color me surprised.

I get a “Translating the Source-- Failed” message for the pondering part, though. Any way to reword that so that Inform is cool with it?

This is what I came up with.

"Shoes"

Use unabbreviated object names.

The Shoe Room is a Room.

Table of Shoe Order
ShoeName	Description	Memory	OrderNumber
flat	"So cute!"	"Not much arch support"	0
boot	"So colorful!"	"Very pointy toes"	0
sandal	"So chic!"	"Very thin sole"	0
sneaker	"So elegant!"	"Doesn't breathe well"	0

A shoe is a kind of thing. Some shoes in the shoe room are defined by the table of shoe order. A shoe can be worn or unworn.  A shoe can be unworn.

Wearorder is a number that varies. Wearorder is 0.

Check wearing a worn shoe: say "You already tried it on!" instead.

Check wearing an unworn shoe:
		choose the row with a shoename of the noun in the table of shoe order;
		say "You put [the noun] on your foot and frown, because [memory entry]!";
		now the noun is worn;
		increment wearorder;
		now the ordernumber entry is wearorder instead.
		
Understand the command "ponder" as something new. Understand "ponder" as pondering. Pondering is an action applying to nothing.

Carry out pondering:
	if wearorder is 0:
		say "No shoes have been tried on yet!";
	otherwise:
		repeat with newvalue running from 1 to wearorder:
			choose the row with a ordernumber of (wearorder minus newvalue minus 1) in the table of shoe order;
			say "[shoename entry] - [memory entry] - [ordernumber entry]!";

Test me with "ponder / x flat / x boot / x sandal / x sneaker / wear flat / wear boot / wear sandal / wear sneaker / ponder".

Tables can be a little tricky do deal with and you have to get the order right for this line. I learnt this the hard way!

Some shoes in the shoe room are defined by the table of shoe order.

But I believe it does what you need!

Hope this helps!

2 Likes

Super helpful, thanks!

I do get a run-time problem message when running it, though:

*** Run-time problem P21: Attempt to look up a non-existent correspondence in the table ‘Table of ShoeOrder’

This problem is probably the one most often seen when dealing with tables, and is usually a symptom that one has forgotten to worry about an unlikely case. It happens when, for instance, we look up the fruit corresponding to a seed count of 10 in the Table of Fruits but the value 10 never occurs in any row of that table, so that there is no such fruit. If we don’t know for certain that this won’t happen, we can always check by testing if there is a fruit corresponding to a seed count of 10 in the Table of Fruits.

I hate tables. I have seen this message many times while trying to get a table to work, and this is one of the many reasons why I don’t do tables. If I see this or something like it, I give up and do a long, elaborate nested if statement instead.

That’s strange! I go that too but I fixed it and it seems to work for me. Are you using Inform 10.1.2?

1 Like

Nope, still stuck in the past. I have a litany of excuses why I haven’t made the change and all of them are very convincing, I assure you.

1 Like

Not to change horses in midstream, but lists are often a way lower-overhead approach for this sort of thing - you could just have an “add shoememory to memorylist” statement the first time the player tries on a particular shoe (or just add the shoe, and then have the relevant say statement be “show shoememory of entry N in memorylist”), and you’re pretty much there.

It’s probably more work than it’s worth to swap over at this point, but might be useful for next time?

1 Like

Try changing

(wearorder minus newvalue minus 1)

to

(wearorder minus newvalue plus 1)

This is the line that caused the error for me. Just need to adjust the offset until it works.

Funny thing is that I originally got it working in 6M62 first. Then realised and switched to the latest version!

2 Likes

Argh, no. I still get the same run-time problem.

Edit: I’m actually starting the OrderNumber from 8, not 0. Could that be the issue?

I dislike tables so much that I might do this, although I’ve never done one before and it looks about as complex as tables from scanning the docs. I am kind of regretting taking on a project with all this tracking of orders and values.

Definitely! In tha case you’ll need to offset it by 8 more. I’d try +/- 7/8/9. I believe one of them should work depending on the circumstances.

1 Like

No tables, minimal lists:

The lab is a room.

A shoe is a kind of thing. A shoe can be shoe-worn. 
A shoe has a number called the shoe wear order. The shoe wear order is usually 0.
A shoe has a text called the memory. The memory is usually "".

The sandal is in the lab. It is a shoe. The description is "So cute!". The memory is "Very thin sole".
The sneaker is in the lab. It is a shoe. The description is "So colorful!". The memory is "Doesn't breathe well".
The boot is in the lab. It is a shoe. The description is "So chic!". The memory is "Very pointy toes".
The flat is in the lab. It is a shoe. The description is "So elegant!". The memory is "Not much arch support".

WearOrder is a number that varies. WearOrder is initially 0.

Instead of wearing a shoe:
	if the noun is shoe-worn:
		say "You already tried it on!";
	otherwise:
		say "You put [the noun] on your foot and frown, because [memory of the noun].";
		now the noun is shoe-worn;
		increment WearOrder;
		now the shoe wear order of the noun is WearOrder;
		
		
Pondering is an action applying to nothing. Understand "ponder" as pondering. 

Carry out pondering:
	let ws be the list of shoe-worn shoes;
	sort ws in shoe wear order order;
	repeat with S running through ws:
		say "[shoe wear order of S] [S]: [memory of S][line break]";
		
4 Likes

OK! Got it working. Thanks a million for the help. Now I have to see if I can understand why that works.

Next time for sure. Down with tables. Thanks for the help, Phil!

2 Likes

That’s a good way of doing it while avoiding tables! I believe you can go one further and use this.

repeat with S running through shoes:

but then sorting doesn’t work so nicely, if at all.

2 Likes

a variant: one list, no numeric order value.

lab is a room.

A shoe is a kind of thing. a shoe is always wearable.
A shoe has a text called the memory.

worn-list is a list of shoes that varies.
Trying it on is an action applying to one thing.
Understand "wear [shoe]", "try [shoe] on", "try on [shoe]" as trying it on.

The sandal is a shoe in the lab. The description is "So cute!". The memory is "Very thin sole".
The sneaker is a shoe in the lab. The description is "So colorful!". The memory is "Doesn't breathe well".
The boot is a shoe in the lab. The description is "So chic!". The memory is "Very pointy toes".
The flat is a shoe in the lab. The description is "So elegant!". The memory is "Not much arch support".

check trying a shoe on when the noun is listed in worn-list: instead say "[We]['ve] already tried those."

carry out trying a shoe on: add the noun to the worn-list.

report trying a shoe on: say "You put [the noun] on your foot and frown, because [memory of the noun].";	
		
Pondering is an action applying to nothing. Understand "ponder" as pondering. 

Carry out pondering:
repeat with S running through worn-list begin;
say "[S]: [memory of S][line break]";
end repeat;
2 Likes

I have it working, thanks to your help, but now I’ve changed my mind about the order-- I originally wanted then listed in reverse order (largest to smallest), which is going great with this code, but now I want it smallest to largest. I’ve futzed with it trying to get it reversed but can’t seem to figure it out.

And if I ever want to do something like this again, I’ll definitely try a list, but I’ve got this system working (almost) and I’m loathe to reinvent it at this point.

Easiest way might be to just do:

Sort the Table of Shoe Order in reverse OrderNumber order;

in the pondering carry out rule, and then just repeat through the rows.

(I haven’t tested this, so not sure whether the fact that you’ve got “order” in the table name would confuse things – probably not?)

1 Like

No, that doesn’t seem to change anything no matter where I stick it in the code. Still runs biggest to smallest. Like I do most things, this is a patchwork of code where the first 8 numbers happen in a prescribed order and are easily printed with “carry out pondering.” But because the second 6 things could happen in any order the player decides, that’s why I needed this table to avoid a huge amount of nested ifs. So maybe I should just redo the whole system to fit in this table, but I absolutely hate screwing with something that currently works (almost). I’ve done dozens of permutations of the code Climbingstars gave me to see if I could reverse the order so it picks up at 9, then 10, etc, but I can’t figure it out. Everything I try either won’t compile, gives me that awful run-time error, or starts those numbers at 10 and works down, so the list reads:
1.)
2.)
3.)
4.)
5.)
6.)
7.)
8.)
10.)
9.)
etc

1 Like

Blarg, sorry, I think I’m having a hard time holding what the code actually looks like in my head. Is it possible to pull out a scaled-down version of the actual code so I can try to bang on it for a bit? Or is that too tricky given how scattered everything currently is?

1 Like

It’s shocking that you can’t read my scattered mind. I tried to pull a reasonable facsimile of the code together, but it’s just too patchwork to do it legibly, and now I’ve messed with it so much that I’ve screwed it up again. Time to start from scratch, I think. Maybe I’ll look at that list code. I need to quit doing things that are so far above my abilities.

1 Like