Assigning traits to generic objects

I have a kind of armor. I want to assign traits to that armor. I could do this by listing the name, description, cost, weight, etc. for each until I fill out pages of text describing all the armor. For convenience, I want to assign these traits from a table so that I can see and compare them all together in one few-inch space.

Armor is a kind of equipment. Armor is wearable. Armor has a number called AC.

Table of Body Protection
Armor		Cost	Weight	AC
padded robe	0.5	3.0	11
leather armor 	15.0 	20.0	13
chain mail	75.0 	50.0	15
plate mail 	400.0	80.0	17
shield wooden	1.0	5.0	1
shield metal	5.0	15.0	2

To initArmorTable:
	repeat through the Table of Body Protection:  
		assign traits to Armor entry consulting Table of Body Protection; 
		now AC of armor entry is AC entry; 

To assign traits to (LocalItem - a thing) consulting (LocalTable - a table name):
	choose row with an item of Localitem in Localtable;
	now cost of LocalItem is cost entry;
	now weight of LocalItem is weight entry;

I get the error that the Armor entry is a kind, and cannot be assigned into a table. I don’t understand this. I have done this elsewhere when I assign Spell traits when each spell is a kind.

A spell is a kind of thing. Bless is a spell. Light Healing is a spell. 

Table of Clerical Master Spells
Spell (spell)	Casting (number)	Notes (text)
Bless	1	"+1 to hit, -1 to be hit for one battle"
Light Healing	1	"Heals d8+1 HP dmg"

to initClericalSpells:
	repeat through the Table of Clerical Master Spells:
		assign traits to Spell entry consulting Table of Clerical Master Spells; 

To assign traits to (LocalItem - a thing) consulting (LocalTable - a table name):
	choose row with Spell of Localitem in Localtable;
	now casting of LocalItem is casting entry;
	now notes of LocalItem is notes entry;

Can someone point out the difference between the armor and the spells, please; and what I should do differently?

EDIT: I should point out that Equipment has a real number called cost and weight;
and Spells have traits Casting and Notes.

For one thing, it doesn’t seem like you’ve defined what “padded robe“ and “chain mail” and such are. You’ll notice that you established “bless“ and “light healing” as spells outside of that table; that’s a huge part of the difference. It wants to match existing armors there. You would need to:

A: declare them, or…

B: Write “Some armor is defined by the table of body protection.“ which, given how you want to initialize things at large, you probably don’t want to do.

Aside from that, “choose row with an item of Localitem in Localtable;” isn’t doing anything here it seems. Inform doesn’t know what “item” is, and my previous examples used it as a declared temporary variable. Do you want to use this “assign traits to” line of code with other tables? If so, it would be best to give all of those “item” entries a universal name. I’ve chosen “gear” for my example.

The garden is a room.

Equipment is a kind of thing. Armor is a kind of equipment. Armor is wearable. Armor has a number called AC.

Some armor is defined by the table of body protection.

Table of Body Protection
Gear (an armor)	Cost	Weight	AC
padded robe	0.5	3.0	11
leather armor 	15.0 	20.0	13
chain mail	75.0 	50.0	15
plate mail 	400.0	80.0	17
shield wooden	1.0	5.0	1
shield metal	5.0	15.0	2

To initArmorTable:
	repeat through the Table of Body Protection:  
		assign traits to gear entry consulting Table of Body Protection; 
		now AC of gear entry is AC entry; 

To assign traits to (LocalItem - a thing) consulting (LocalTable - a table name):
	choose row with a gear of Localitem in Localtable;
	now cost of LocalItem is cost entry;
	now weight of LocalItem is weight entry;

If “padded robe” is a single padded robe and not an entire categorization of padded robes within your world, this should be fine. If “padded robes” are a kind of armor…

You might be better off going “A shield metal is a kind of armor. The cost of a shield metal is usually 5.0. The weight of a shield metal is usually 15.0. The AC of a shield metal is usually 2.“.

It sounds like what you want is possibly Some kinds of armor are defined by the Table of Body Protection.… but unfortunately that syntax was broken in 10.1.

1 Like

Wouldn’t you first define Trait with properties, then each specific Trait? Why use a table when the language lets you type your traits?

A. I have previously defined all the armor with associated descriptions, which I use as a base for specific armors. I didn’t want to include all those declarative lines of code here.

B. “Some armor is defined by the table of body protection" sounds like a plan. It seems like it will get around the parser error. I’m not sure why I wouldn’t want to add this statement.

Will it define a kind of armor object, or do I still have to declare it (e.g., padded robe is a kind of armor), then assign traits to the object I created by its declaration?

There will be multiples of everything in this table, placed at the appropriate location. These tables only assign values to the armor kinds so all subkinds have those traits. For example, all padded robes have a (base) cost of 0.5 and a weight of 3.

C. Yes, I erroneously used “item” instead of “armor”.

Yes, these are all going to be multiples. Your suggestion of individually declaring the object with every one having the same traits is what I am trying to avoid. (I have done that and for the number of Equipment (Armor, Weapons, Ammo, Outfitting), it works but is unwieldy.

Broken syntax?? What?! The docs already are incomplete for some of the things I’m trying. If I can’t use that syntax, is there something with the same goal I could use?

I think it’s a bug that was introduced by the huge refactor that went into Inform 10. I expect it will be fixed when the next version comes out. In the meantime, your options are to either not use a table (define each kind one by one as usual) or use an older version of the compiler (which you can do in the settings).

For convenience. See the original post. This table replaced PAGES of text for all the items that I have. Individual items (armor, weapons, ammo, equipment) with the same constants are repeated and repeated–too me, bad programming, and inconvenient.

It seems that saying

Some armor is defined by the table of body protection

does create a kind of armor defined by that specific armor in the table. I get the following error:

ERROR: You wrote ''A padded robe is a kind of armor, but that seems to say that some room or thing already created (‘padded robe’, created by '‘Some armor is defined by the table of body protection’ is now to become a kind.

It seems from this error that Padded Robe will be a kind of padded robe, which is exactly what I want. I removed the individual declaration for padded robe (outside the table), and the error went away.

btw, I am using Inform 1.82 (2014-2022). Not sure how that equates to 10.1.

EDIT: It seems that the table did NOT create the object, at least not in the room that I said it should be. Not sure what that means though. Is the room wrong, or does the object not exist?

Uhh, no, that line creates several objects of kind armor. The error you’re seeing is that you tried to define the same name as both an “object of kind armor” and a “kind of armor”, which are two vastly different things.

I guess I want to go back to why can I assign traits to the magic spells but not to the armor?
Is it because the say, Bless spell is a spell object, and not a kind?

Is there no way then to put kinds into a table? and subsequently assign traits to the kind? I’m forced into long list of kind declarations?

There is no way to put kinds into a table in the current release of Inform 10, unfortunately.

:unamused_face: :sob:

What if I put the text name into the table, then match that name with the kind before assigning traits?