I have a room that contains many duplicate things, like 36 arrows, 10 bows, etc. When I SHOWME, I get a list of the many, many…many things, one at a time. I would like to group similar things together, so SHOWME responds with
36 arrows
10 bows
etc.
Inventory and other kinds of listings seem to work fine, but it doesn’t seem to work for SHOWME. I read the Grouping problem already discussed in July 2014.
Any help?
I think hacking SHOWME would be very tough, as that’s close to the metal - I’d just write a custom testing command that displays the info you want in the format you want.
Yeah, SHOWME isn’t implemented in I7 or even in I6; it’s a hardwired part of the compiler itself, which generates the appropriate code for each object to show all the properties it supports. Changing it would be extremely difficult. Much easier just to write your own.
Where there’s a truly stupid amount of will, there’s a way:
lab is room.
arrow is a kind of thing. there are 37 arrows in lab.
the player carries a closed box.
toy is in the box.
The puppy is an animal.
the collar is a supporter.
the tag is on the collar.
the puppy wears the collar.
the puppy is in the basket.
the player carries the basket.
to say showme (o - object): (-
@push noun;
noun = {o};
ShowMeSub();
@pull noun;
-)
showmeing is an action applying to one visible thing.
understand "showme [any object]" as showmeing.
carry out showmeing:
let t be "[showme noun]";
let l be a list of texts;
let count be 1;
repeat for line in lines of t begin;
if the number of entries in l > 1 and the substituted form of "[line]" is entry (number of entries in l) of l begin;
increment count;
next;
end if;
if count > 1 begin;
now entry (number of entries in l) of l is the substituted form of "[entry (number of entries in l) of l] ([count])";
now count is 1;
end if;
add the substituted form of "[line]" to l;
end repeat;
repeat with m running through l begin;
say m;
say line break;
end repeat;
test me with "showme lab".
Include (-
[ textWipe t i;
for (i = 0 : BlkValueRead(t,i) : i++ ) BlkValueWrite(t,i,0);
];
-)
To repeat with/for (loopvar - nonexisting text variable) running/-- through/in lines in/of (t - text) begin -- end loop: (-
{-my:0} = {t}-->0;
@push {-my:0};
{-my:1} = TEXT_TY_Temporarily_Transmute({-by-reference:t});
@push {-my:1};
for ( {-my:1} = BlkValueLBCapacity({-by-reference:t}) - 1 : {-my:1} >= 0 : {-my:1}-- ) if (BlkValueRead({-by-reference:t}, {-my:1})) { {-my:1}++; break; }
BlkValueSetLBCapacity({-by-reference:loopvar}, {-my:1}+1);
TEXT_TY_Transmute({-by-reference:loopvar});
for ({-my:0} = 0, {-my:2} = BlkValueRead({-by-reference:t}, 0), {-my:3} = 0 : ({-my:0} <= {-my:1}) : {-my:2} = BlkValueRead({-by-reference:t}, ++{-my:0}))
if ({-my:2} && ({-my:2} ~= 10)) { BlkValueWrite({-by-reference:loopvar}, {-my:3}++ , {-my:2}); }
else for ( : {-my:3} : {-my:3} = 0, textWipe({-by-reference:loopvar})) {-block}
-)
produces
>test me
(Testing.)
>[1] showme lab
lab - room
yourself - person
closed box - open container
toy
basket - open container
puppy - animal
collar (worn) - supporter
tag
arrow - arrow (37)
lighted, visited; singular-named, proper-named
description: none
printed name: "lab"
printed plural name: none
indefinite article: none
list grouping key: none
>
While I thank you for your tremendous effort on my part, I have no clue how to use I6, although I could copy your code verbatim. However, your example did not show duplicates, which is actually the problem. I think I can write an action to group together all duplicates of the same kind and number, like inventory does automatically).
I have an area called VSpace that stores all my items. Each item has a PID number so that I can match and retrieve what’s in VSpace with what is displayed in any one of various rooms. Why do I do this? Duplicates are handled differently than different objects, and causes trouble when I have the same duplicate in three different places, e.g. carried by player, in Emporium, or in Stadium; and especially when the player is carrying a duplicate in a room with another duplicate of the same kind. I think I have it figured out now so that it works correctly, but I wanted that SHOWME diagnostic tool to help during testing.
To find the grouped-together number of duplicates in VSpace, I think I can loop through all items in VSpace and count those with the same PID. That should give me a result such as “36 arrows”–instead of 36 lines that say “an arrow”. Thoughts?
I used this code to count specific items in my storage Closet.
Counting is an action applying to nothing.
Understand "count" as counting.
Carry out counting:
let Nleather be number of leather armors in Closet;
let Nchain be number of chain mail in Closet;
let Nbow be number of recurve bows in Closet;
let Narrow be number of arrows in Closet;
say "[Nleather] suits of leather armor[line break]";
say "[Nchain] suits of chain mail armor[line break]";
say "[Nbow] recurve bows[line break]";
say "[Narrow] arrows[line break]";
However, I need to count everything in the Closet when I don’t know the specific items that are in there. I would like to loop through all items in the Closet, but actions cannot be defined for rooms.
Somehow INVENTORY does exactly what I want, but it doesn’t happen for the SHOWME command. Any suggestions?
I put my storage space Closet as “some-object” and it worked great!
Thanks!
Is there an easy way to show numerals instead of word descriptions? For example, to have the contents listed as
“36 arrows”
instead of
“thirty-six arrows”.
Is there a replacement text to do that?
??? What? I’m not aware of any rule that forbids defining actions for rooms… though I also don’t understand why you’d think you need that here.
There doesn’t seem to be a phrase option on list the contents of to do that. You could always manually iterate via repeat with T running through things in some-object, and then you have full control over the format, but you also need to take care of recursing if necessary.
for printing a number of something (called the item) (this is the printing a numeric number of something rule):
say "[listing group size] ";
carry out the printing the plural name activity with the item;
As written, this would also affect inventory output and all other uses of the list the contents of phrase so you’d want to qualify it somehow so this rule only applied during your debugging.
Snuffling is an action applying to one room.
Understand "snuffle" as snuffling.
and you get this error: Problem. You wrote ‘Snuffling is an action applying to one room’: but an action can only apply to things or to kinds of value, for instance: ‘photographing is an action applying to one visible thing’.
(The index shows a room to be different from a thing.)
Counting is an action applying to one thing.
Understand "Count [room]" as Counting.
Carry out Counting:
list the contents of noun, with newlines, indented, including all contents;
I get the response
“You can’t see any such thing.”
regardless of which room the player is in.
I agree with that. It seems more than I keep many objects in some storage room, like Closet or VSpace, and move them in and out of play. Being able to count what’s in storage (with numbers) seems something that could be part of Inform.
That’s because rooms aren’t in scope for player actions by default – you can do that either globally, by making the grammar “snuffle [any room]”, which will allow you to use the action on any room regardless of where on the map you’ve been, or manually, with something like:
After deciding the scope of the player while snuffling:
place the location in scope.
Which will allow the action to work for the current room but not others.
Great tip! Thanks. I didn’t know you could place a location in scope.
In my case, all unused (and unlocated) objects are “stored” in a single room called VSpace (basically out of play). I’ve had it hardcoded by name, but it would be nice to see what is where when I’m not in a location and I want to see what’s in that other location.