Removing and replacing items in a container

I guess I’m getting tired. Is there an easy way for the player to take and replace duplicate items in a container? Ex: I have a container called lantern with 4 candles in it. (First, duplicates cause trouble right off the bat.) Now I want the player to remove candle from lantern, so the number of candles is now 3 in the lantern, and 1 in the inventory. Eventually, all candles can be removed, and even one or two put back.

I was thinking of using a list with one candle but a number of entries called 4, which gets reduced. Then the problem of the printout contents of lantern appears.
Help?

1 Like

Hmmm, have you looked at 4.14. Duplicates?

All you should need is:

The lantern is a container.
A candle is a kind of thing.
There are 4 candles in the lantern.

You can type ‘take 3 candles’ and take 3 candles, or take 1 candle, etc.

4 Likes

Yes, I have looked at that until my eyes cross. It doesn’t work as expected. It seems to distinguish a candle from 4 candles, treating ‘4 candles’ as a new object.
NOTE: [1] I have the TAKE ALL command turned off, so perhaps the multiples is not recognized because of that.[2] I have another candle that is in a candlestick. Whenever I examine candle, I always get the candlestick candle.

2 Likes

It might help if you post your code here as well, so we can see. What you described is exactly what would happen if you left out the line ‘a candle is a kind of thing’, but there might be a different issue causing a conflict.

2 Likes

This is almost certainly the issue – unless you’ve knocked it out with something like “Understand ‘TAKE ALL’ as a mistake”, what you’ve actually done is disable the ability to take more than one thing at a time, not just the ability to take everything in a location at one time.

EDIT: actually, looking at the solution you wound up going with in the other thread, not sure that would cause this issue – so I’ll just second Brian and suggest posting a cut-down example from your code that demonstrates the issue!

3 Likes

This means it’s not recognising “candles” as a the plural of a kind, and so it doesn’t see “4 candles” as 4 x candles, but as a new thing. Check you haven’t mistyped a word somewhere!

I feel we’re verging dangerously close to fork handle territory here.

1 Like

My ultimate goal is to remove 1 to 4 candles from a candle-lantern and be able to light them (or blow them out) as needed. I have been having trouble distinguishing individual candles from multiples so I built this sandbox. Everything works fine for a single candle (‘candle is a thing’) but as soon as I add two candles and make ‘candle is a kind of thing’ to handle multiples, it doesn’t know how to light them.

"Sandbox" by Clyde Falsoon

Test room is a room. Test room is dark.
Description of test room is "You are in a large empty room that won't be harmed by an errant fire. The room is [if candle is lit]lighted.[else]dim.[end if]".

A flame is in test room. 
A stone is in test room.

[A red candle is a candle.  A blue candle is a candle.]

A candle is a kind of thing. A candle can be lit or unlit. It is usually unlit. 
Description of candle is "The white eloquent candle is [if candle is lit]lit.[else]unlit.[end if]".
There is a red candle and a blue candle in the test room.

[For purposes of testing lighting the candle]
A flame is a thing. It is lit. Description of flame is "Flame is a metaphysical construct.".
Instead of dropping flame:
	now flame is nowhere;
	say "[list of all lit things in location of player]".

Understand "burn [candle]" as burning.
Understand "light [something]" or "ignite [something]" as burning. 

The block burning rule is not listed in the check burning rules.

Before burning a noun:
	if noun is not a candle:
		say "You can't light that!";
		stop the action;
	otherwise:
		if flame is in location of player or player carries a lit thing:
			now noun is lit;
			say "[description of noun][line break]";
			say "[description of test room]";
		otherwise:
			say "You need a flame to light a candle.";
			stop the action.	

[Candle Actions]
Understand "blow out [something]" or "extinguish [something]" or "put out [something]" as blowing out. Understand the command "snuff" as "extinguish". 

[BLOWING OUT SOMETHING LIT.]
Blowing out is an action applying to one thing.

Check blowing out an unlit thing:
	say "[We] can only put out things which are lit." instead.

Carry out blowing out:
	now noun is unlit;
	now test room is dark;

Report blowing out:
	say "[We] [put] out [the noun][if the noun is a candle].[one of] A small thread of smoke rises as the wick cools.[or]The flame flickers out with a puff.[or]The room's visibility decreases[or]You extinguish the flame, leaving a short turbulent stream of white smoke that quickly dissipates.[at random][end if]";

I have never got the hang of how to disambiguating duplicates. Since my story contains lots of different kinds of candles, I am in deep darkness.

1 Like

I think the issue you’re getting here is that your red candle and blue candle aren’t of the kind “candle” – just including the name of a kind in the name of an object doesn’t automatically make it one of the mentioned kind (which is good, because otherwise the red door key might turn out to be a door!) Try subbing in this line:

The red candle and blue candle are candles in the test room.

6 Likes

Yes, that worked. Now I have to deal with four duplicates in the candle-lantern, another four lanterns, that are a kind of candle, and a stuck_candle that is stuck in a candlestick. Thanks for the push.

1 Like

Given four candles in a container: I want to light one (or more) of the four. Do I need to give them all names? I’ll soon run out of colors, and that seems immensely awkward. I can give them numbers, but how will the player know how to distinguish them?

1 Like

If you don’t want to make them distinguishable, you can just make them identical duplicates and then the player should be able to refer to lit or unlit candles. You might want to update the printed name so players can tell at a glance how many are lit, though.

You might also want to include a Does the player mean rule to make this easier:

Does the player mean burning an unlit candle: it is very likely

1 Like

OK, I think I have the sandbox working as I want it. I think there must be something in the context code of my story that is causing the story not to work like the sandbox. I’ll have to look into that. Thank to all for the assistance.

"Sandbox" by Clyde Falsoon

Test room is a room. Test room is dark.
Description of test room is "You are in a large empty room that won't be harmed by an errant fire. The room is [if candle is lit]lighted.[else]dim.[end if]".

A candle is a kind of thing. A candle can be lit or unlit. It is usually unlit. 
Description of candle is "The candle is [if candle is lit]lit.[else]unlit.[end if]".

A flame is in test room. 
A stone is in test room.
A box is in test room. Box is a container. Carrying capacity of box is 4.
There are 4 candles in box.
A table is in test room. Table is a supporter. 
Description of table is "A normal table in the center of the room. [if a candle is on table]There [are] [number of candles] candles on the table.".

After putting a candle on the table:
	Let N be the number of candles on the table;
	Let L be the number of candles that are lit on the table;
	say "There [are] [N] candle[s] on the table; [L in words] candle[s] [are] lit.";

test candling with "take candle from box/ light candle/ put candle on table/ take candle from box/ light candle/ put candle on table/light candle/ put candle on table/look/ blow out lit candle/ put candle in box/ put lit candle in box/look".


[For purposes of testing lighting the candle]
A flame is a thing. It is lit. Description of flame is "Flame is a metaphysical construct.".
Instead of dropping flame:
	now flame is nowhere;
	say "[list of all lit things in location of player]".

Understand "burn [candle]" as burning.
Understand "light [something]" or "ignite [something]" as burning. 

The block burning rule is not listed in the check burning rules.

Before burning a noun:
	if noun is not a candle:
		say "You can't light that!";
		stop the action;
	otherwise:
		if flame is in location of player or player carries a lit thing:
			now noun is lit;
			say "[description of noun][line break]";
		otherwise:
			say "You need a flame to light a candle.";
			stop the action.	

[Candle Actions]
Understand "blow out [something]" or "extinguish [something]" or "put out [something]" as blowing out. Understand the command "snuff" as "extinguish". 

[BLOWING OUT SOMETHING LIT.]
Blowing out is an action applying to one thing.

Check blowing out an unlit thing:
	say "[We] can only put out things which are lit." instead.

Carry out blowing out:
	now noun is unlit;
	now test room is dark;

Report blowing out:
	say "[We] [put] out [the noun][if the noun is a candle].[one of] A small thread of smoke rises as the wick cools.[or]The flame flickers out with a puff.[or]The room's visibility decreases[or]You extinguish the flame, leaving a short turbulent stream of white smoke that quickly dissipates.[at random][end if]";
2 Likes