Filling in thing properties from a table

I’m trying to set up a chemical puzzle, I want a bunch of chemicals and I figured it would be more readable to set them up using a table. The “proper” way doesn’t work right now according to Defining things with tables results in adding properties at the room level - #4 by Monsieur.HUT * , but filling out item properties from the table should work?

Except the below snippet gives me a " Run-Time Problem Attempt to look up a non-existent entry in table (P23)":

"Test" by Hellzon

A thing has some text called smell.
A thing has a text called taste.
A thing can be poisonous. A thing is usually not poisonous.

The Chemical lab is a room.

A chemical bottle is a kind of thing.
A chemical bottle has a text called the hue.
A chemical bottle has a text called the consistency.
A chemical bottle has a number called the CID.
A chemical bottle is usually not poisonous.
The description of a chemical bottle is usually "[A noun] half-full of [hue] [consistency].".

A poison bottle is a kind of chemical bottle. A poison bottle is usually poisonous.

Report tasting a chemical bottle:
	Say "The contents of [the noun] [taste] [taste of the noun]." instead.

A tall round bottle is a chemical bottle in the Chemical Lab. The CID is 101.
A short conical bottle is a poison bottle in the Chemical Lab. The CID is 201.

When play begins:
	repeat with X running through chemical bottles:
		If there is a Chemical-number of (the CID of X) in the Table of Chemicals: [for testing]
			choose the row with Chemical-number of the CID of X in Table of Chemicals;
			now the hue of X is "[Colour entry]";
			now the consistency of X is "[Formulation entry]";
			now the smell of X is "[Odour entry]";
			now the taste of X is "[Mouthfeel entry]".
		
Table of Chemicals
Chemical-number	Colour	Formulation	Odour	Mouthfeel	
101	"white"	"powder"	"a hint of cinnamon"	"sweet"
201	"orange"	"granules"	--	"salty"


The Index tells me that the two bottles are indeed getting the “CID” properties correctly, but nothing else is being assigned. Presumably I’m doing something wrong with the choosing of rows or setting variables?

*) Tested that one. Yeah, everything in the game world got colour, consistency, smell and taste variables.

The problem seems to be the missing “Odour” entry for 201. That’s the non-existent entry. If you add a text there, the error should go away.

1 Like

Oof. That did it. Thanks!

I could ask a follow-up question about why it worked “fine” when I used the proper table method, but I suppose that’s how the system works and there are safeguards against empty entries.

You could do the equivalent by writing:

			if there is an odour entry:
				now the smell of X is "[Odour entry]";

By the way, this is a case where you can simplify the punctuation:

			choose the row with Chemical-number of the CID of X in Table of Chemicals;
			now the hue of X is Colour entry;
			now the consistency of X is Formulation entry;
			now the smell of X is Odour entry;
			now the taste of X is Mouthfeel entry.

Colour entry is a text; that’s how the table is defined. Writing "[Colour entry]" creates a new text whose contents are that text, which is the same result, but takes several extra function calls in the generated code.

2 Likes