Defining new kinds of things using repeat and table entries

I have a table and I’d like to use the entries from a particular column of the table to create new variables; specifically, a kind of thing for each entry.

I know the code for running through the column and capturing each entry into a temporary variable works, but I can’t seem to deduce how to then take that and use it as the object name to define a new kind of thing.

When play begins: repeat through the Table of Provisions: let M be the consumable entry; XXXX is a kind of edible thing; now the player carries XXXX.

…where XXXX would be the object named M.

And, for reference, the Table looks something like this:

Table of Provisions Consumable Health Feeling Inspection "apple" 2 "a tiny bit" "A healthy snack that will help you regain a very small amount of stamina." "banana" 2 "a little bit" "A healthy snack that will help you regain a little stamina." "cheese" 4 "significantly" "A wheel of cheese. A must-have for any adventurer who has taken an arrow to the knee."

(Apologies if the columns don’t line up. I’m not sure how to do that.)

Effectively, what the code should do is create an apple kind of edible thing, then give the player an apple; create a banana kind of edible thing, then give the player a banana; and create a cheese kind of edible thing, then give the player cheese.

I know I could easily define these kinds outside of a loop and a table, but the idea is one of authorial simplicity–simply fill out the table, and the game will do the rest of the work for you, irrespective of how many objects you create. Think of it like a tool.

Any suggestions on the above would be greatly appreciated. I’m still at the point with Inform 7 of writing three lines of code, then spending 1 hour trawling the internet trying to work out how to do what I want it to, with the correct syntax. I thought it was about time I made use of posting in this forum rather than just searching it (so thank you for everyone who has ever answered a beginner’s query such as mine!)

Your problem is using text for the kind names. This is a fairly uncommon use case, but you can find examples in the “Reliques of Tolti-Aph” sample game.

[code]Food is a kind of thing. Food is usually edible. Some kinds of food are defined by the Table of Provisions.

Table of Provisions
name health feeling description
apple 2 “a tiny bit” “A healthy snack.”[/code]

Basically, the first column needs to be called “name”, and the names need to be unquoted (because they’re kind names, not text).

Notably, new kinds can’t be created at run-time; they have to be defined at compile-time.

Thanks for the tips, @Draconis.

I’ll revisit your answer in detail tonight when I get to sit down and code. But if I understand you correctly, so long as I change the name to an object rather than text and place the code into a section that compiles before play begins, it should work…?

I’ll let you know how I go tonight.

Thanks, again!

With a bit of reworking of the rest of my surrounding code, it works wonderfully.

Thanks again, Draconis. I had no idea you could define variables directly from a table.

It’s again a very unusual use case, but it’s wonderfully convenient when you need it! You can define either objects directly (“Some foods in the Pantry are defined by…”) or kinds of object (“Some kinds of food are defined by…”).