I found some conversions from player’s commands to numbers elsewhere, but nothing seemed to be really solved–except for some ethereally mysterious I6 code.
What I want to do applies to duplicates in inventory: If there are 5 arrows weighting 1 oz each, then when the inventory prints, I want to see 5 arrows (5 oz) instead.
Inventory already sums the number of items but that first word seems to be text, not a number.
This part works:
After printing the name of something (called the Item) while taking inventory:
let N be the weight of Item;
say " ([N] lb)" ;
but when I try to convert the word (?) in the list (multiple object list?), I get the error that says Item is a temp variable and doesn’t apply. Problem. You wrote ‘let W be the number of characters in Item’, but ‘Item’ is a temporary name for a thing (created by ‘let’ or ‘repeat’), whereas I was expecting to find a text there.
Can someone explain this to me, and offer a suggestion on how to get the arrow tally?
I can explain this, but I’m not sure what you’re trying to do with it re: what you want to get (the total arrow weight), and I don’t have a quickie solution for that either.
But that’s a pretty good error message from Inform there. It wants a text, not a thing. You can ask for the number of characters in “apple”, but not the number of characters in apple, the thing in the game. The relevant question would be (to a human) “how many characters are there in the printed name of the apple thing?”
Try let W be the number of characters in "[Item]";
Lab is a room.
A thing has a number called the weight.
A turnip is a kind of thing. A potato is a kind of thing. A turnip has weight 1. A potato has weight 2.
Ten turnips are carried by the player.
Ten potatoes are carried by the player.
After printing the name of something (called the Item) while taking inventory:
let N be the weight of Item;
say " ([N] lb)" ;
After printing the plural name of something (called the Item) while taking inventory:
let N be the weight of Item * listing group size;
say " ([N] lb)" ;
I did what you said (I forgot about this text token) and the parser error went away.
What I am trying to do is convert “5 arrows” which shows up in the inventory to the number 5 so that the total weight of 5 arrows is 5 * the weight of each arrow, so that it prints after it is printed in the inventory list.
There is something funky going on here in inventory. The plural items and weights are working fine, but the single ones are doubling up on the weight. The rule is almost trivial so I don’t see where the problem is.
Player carries leather armor, backpack, and 5 arrows.
Player has a real number called wtCarried.
Before taking inventory:
now wtCarried of player is 0.0;
After taking inventory:
say "Total Weight = [wtCarried of player]";
After printing the name of something (called the Item) while taking inventory:
let N be the weight of Item;
increase wtCarried of player by N;
say " ([N] lb)" ;
After printing the plural name of something (called the Item) while taking inventory:
let N be the weight of Item * listing group size;
increase wtCarried of player by N;
say " ([N] lb)" ;
I notice that the (open) state of the backpack is printed after the AFTER printing item rule is executed. Somehow the wt data is printed in-between. Can that cause this effect?
Instead of calculating wtCarried of player in the after printing rules, do it all at once:
After taking inventory:
now wtCarried of player is 0;
repeat with X running through things enclosed by the player:
increase wtCarried of player by weight of X;
say "Total Weight = [wtCarried of player]";
The problem with the original approach is that Inform sometimes needs to “say”/“print” text into its own internal buffers to compare it, measure it, whatever, and sometimes this results in a particular printing/saying piece of code being run more than once! Hence making your weight off. Apparently it needs to do this for the container (perhaps to measure for indentation? I don’t know).
lab is room.
Weight is a kind of value. 10lb specifies a weight.
Things have a weight.
the verb to weigh means the weight property.
box is a container in lab. box weighs 6lb.
the toy is in box. toy weighs 2lb.
the watermelon is in box. watermelon weighs 5lb.
To decide what weight is the laden weight of (T - thing): [see WWI 15.17 Totals]
decide on total weight of things enclosed by T plus weight of T.
when play begins: say laden weight of box.
This is a great idea but something is wrong with “weight”.
I get this error: Problem. The phrase you describe in ‘To decide what weight is the laden weight of (T - thing)’ seems to be trying to decide a value, but ‘weight’ is not a kind that I recognise. (I had expected something like ‘number’ or ‘object’ - see the Kinds index for what’s available.)
To decide what weight is the laden weight of (T - thing): [see WWI 15.17 Totals]
decide on total weight of things enclosed by T plus weight of T.
After printing the name of something (called the Item) while taking inventory:
let N be the laden weight of Item;
let spacer be " ";
say " [spacer] ([N] lb)" ;
I think the problem is that I use weight as a real number, but the example has weight as a value.
To decide what real number is the laden weight of (T - thing): [see WWI 15.17 Totals]
decide on total weight of things enclosed by T plus weight of T.
I think this gives me the proper result:
To decide what real number is the laden weight of (T - thing): [see WWI 15.17 Totals]
decide on total weight of things enclosed by T plus weight of T.
After printing the name of something (called the Item) while taking inventory:
let N be a real number;
if Item is closed container:
now N is the laden weight of Item;
otherwise:
now N is the weight of Item;
let spacer be " ";
say " [spacer] ([N] lb)" ;