I have a series of objects defined, all subkinds of Equipment, which has a qty, cost, and weight property. Each object is listed in a display table for buying and selling. However, objects are not allowed in tables, only values and text. I want to set the properties in the table to the object associated with the Item column.
For example, I have 10 torches, cost 3 silver and weight of .2 lb. This is shown in the table. However, I cannot extract the cost and weight and assign it to an object because I donât know specifically what the object is while running through the table. How do I associate the torch object with the properties of the torch row?
I checked out the The Reliques of Tolti-Aph as the docs suggested, but Nelsonâs spells are defined in the table as values. I couldnât see how he associated them with action-based spells.
You can certainly put objects in a table. Though if weâre careful in our terminology here, we should say Things, rather than objects, as they have different meanings in Inform.
Hereâs a sample program that puts a torch in a table. No other code yet, just showing it will compile.
the shop is a room.
a torch is a thing.
table of buys
entity (a thing) cost (a number) weight (a number)
torch 3 0.2
But I can immediately see more problems. In my table, thereâs just one torch. We canât make a torch kind then put that directly in the table, as you found ot.
So there are various approaches. You could make a torch kind, then put ten torches with different behind-the-scenes names in the table, but theyâll have identical behaviour and display names, thanks to the kind. Cumbersome, but works.
Or you can make a torch kind and tie it to the table with some other kind of reference, and create 10 identical torches. Iâm not sure what the best way to do this is off the top of my head. You could give things a shop-reference value, which for the torch would be 1. Then replace âtorchâ with a 1 in the shop table (changing kind to number) and add another number column tracking the inventory remaining. Now when someone buys, the shop-reference number would identify the torch as the thing to give the player, and youâd reduce the inventory value in the table by one on that line.
Someone else may show up with more explicit code, but I just wanted to indicate to you for starters that you can put things in a table, and there is a way to proceed using this method.
Basically, the spell stays a value. You can use his code to do something similar, and then refer to the various values assigned to the buyable items. The items could have internal privately-named versions that are values (torch-value is buyable), connected to their corresponding things by a relation, and then when someone wants to BUY TORCH (âtorchâ referring to a value):
find torch-value in the table and extract the cost and weight
check if the player can afford and carry the item
remove the appropriate amount of money from the playerâs inventory
find the torch that relates to the torch-value
give the torch (thing) to the player.
Hereâs how Tolti-Aph does spells (see the code above for all the stuff I cut out, mostly prevention rules)
A spell character is a kind of value. The spell characters are offensive, defensive, healing and arcana. A valency is a kind of value. The valencies are targeted and untargeted.
A spell is a kind of value. The spells are defined by the Table of Enchantments.
[...]
Casting it at is an action applying to one spell and one visible thing. Rule for supplying a missing second noun while casting: now the second noun is the location.
Understand "cast [spell]" or "[spell]" as casting it at.
Understand "cast [spell] on/at [something]" or "[spell] [something]" as casting it at.
The current spell focus is an object which varies. Before casting, now the current spell focus is the location.
I use this method. The link is a number property of the thing, an UID. Lesser than 10000 : duplicates of a kind. Greater than 10000 : unique objects, created this way too because of the bug with the room properties. That works perfectly.
All these are great ideas, and those that follow from others. I guess that now I need to know how to associated a table thing (such as âgrease-torchâ) to the torch thing. I have been having problems with that which is why I thought my problem was limitations with the table. Are you saying I can use the name of a thing as the entry in the table and it will associate it for me?
I think this is closer to your suggestion, but I canât figure out what I am doing wrong.
All items in this Armor table are defined elsewhere as Equipment->Armor->(specific thing).
To display armor table:
say "ChrAdj = [ChrAdj to two decimal places] ";
let PriceValue be a real number;
say "[line break][bold type][line break] A R M O R[line break]";
say "Armor Qty Cost Weight[line break][roman type]";
repeat through the Table of BodyProtection:
now PriceValue is Cost entry * ChrAdj;
let price be coinage of PriceValue;
now PriceValue is cost of armor entry understood as real number;
say "[fixed letter spacing][armor entry] [qty entry] [cost entry] [weight entry][variable letter spacing][line break]";
now cost of equipment is cost entry of obj;
now weight of equipment is weight enty;
now qty of equipment is qty enty; ]
say "[paragraph break]";
And the table is defined here. I want to set qty, cost, and weight as properties of the specific item. Equipment already has defined those properties for all Equipment kinds.
OK, I got it to work. It was a matter of syntax. This is what I have:
To display armor table:
say "ChrAdj = [ChrAdj to two decimal places] ";
let PriceValue be a real number;
say "[line break][bold type][line break] A R M O R[line break]";
say "Armor Qty Cost Weight[line break][roman type]";
repeat through the Table of BodyProtection:
now PriceValue is Cost entry * ChrAdj;
let price be coinage of PriceValue; [text]
say "[fixed letter spacing][armor entry] [qty entry] [price] [weight entry][variable letter spacing][line break]";
now cost of armor entry is PriceValue;
now weight of armor entry is weight entry;
now qty of armor entry is qty entry;
say "[paragraph break]";
Now when I say âshowme robeâ or some other object, the object displays the properties listed in the table for cost, weight, and qty, as desired.
I will assume you are not being sarcastic. In my example blow (forgive the formatting), I use armor in a table to define armor items and constants for those items. Donât put the items in quotes.
Table of BodyProtection
Item Nbr Cost Weight AC
padded robe 2 0.5 1.0 11
leather armor 3 15.0 20.0 13
chain mail 2 75.0 50.0 15
plate mail 1 400.0 80.0 17
shield wooden 3 0.9 5.0 1
shield metal 2 15.0 15.0 2
Then I can display the table:
To display armor table:
let PriceValue be a real number;
say "[line break][bold type][line break] A R M O R[line break]";
say "Armor Nbr Cost Weight[line break][roman type]";
repeat through the Table of BodyProtection: [reading table before displaying]
now PriceValue is Cost entry * ChrAdj;
let price be coinage of PriceValue; [text]
say "[fixed letter spacing][item entry] [nbr entry] [price] [weight entry] [AC entry][variable letter spacing][line break]";
now item entry is in Ganon's Emporium;
now cost of item entry is cost entry;
now weight of item entry is weight entry;
now qty of item entry is nbr entry;
now AC of item entry is AC entry;
say "[paragraph break]";
Note that the armor items are defined and placed into Ganonâs Emporium so the player may buy them; otherwise they are nowhere.
I also noted that the table parser is smart enough to read, say, âshield woodenâ from the table and find the armor item âwooden shieldâ.
Iâm not. Itâs been a while, so Iâd have to go back and look at my code, but for some reason I was never able to get putting things in tables to work. My workaround in the past has been to just make one thing and use tables to cheekily switch its printed name around. So thanks, all of this is very helpful.
Ah, I see, thanks for clearing that up. That explains my bewilderment. I didnât know about that bug, and that it affects defining things with tables specifically. Guess I should have read the thread more carefully!