Inventory stacking // containing multiple items // Rule for multiple of the same item

So I’ve gone so far and can only go so far without asking:

How does one go from having a singular eg.

a Zorkmid is a kind of thing
Copper Zorkmid is a Zorkmid

to many being allowed to exist eg.

a Zorkmid is a kind of thing
Copper Zorkmid is a Zorkmid
The Plural of Copper Zorkmid is Copper Zorkmids
There are 300 Copper Zorkmids

to then placing a few in the world (or specifically containers) ( i dont have an eg I cant find a way to work)

this way though for eg. does not work

The Testing Crate is a thing in The Central Yard. 
The Testing Crate is undescribed.
The Testing Crate can be open or closed.
The Testing Crate is closed.
instead of opening The Testing Crate:
	now The Testing Crate is open;
	say "The Testing Crate clicks open.".
	
instead of closing The Testing Crate:
	now The Testing Crate is closed;
	say "The Testing Crate shuts.".

The Testing Crate contains 3 copper zorkmids.

this instead creates an item called 3 copper zorkmids.

in addition to this i would like when you take a copper zorkmid (or any amount of) that for each which you take it should

PlayerZorkmidBalance is a number that varies.
PlayerZorkmidBalance is 0

instead of taking a copper Zorkmid:
	now PlayerZorkmidBalance is PlayerZorkmidBalance + 1;
	continue the action..

say i was to take 5 copper zorkmids from a chest it should list it in the inventory as

5x Copper Zorkmids
[Image of Zorkmids]

also taking the (X amount) bunch from the chest should print as “You take (X amount) Zorkmids”

help :frowning:

If you want multiple identical, stackable items to exist, you need to create them as a kind, not an instance of a kind; in your code above, “Copper Zorkmid” is a specific instance so it’s not going to do what you want, but you could write things like “there are six zorkmids in the chest” and then the player would be able to pick them up individually or at once, and they’d stack.

Another approach to a money system is the “have a single object with a quantity property” one you mention later in your post, but these are pretty much mutually exclusive - I’d pick one or the other. There have been some good recent threads laying out that approach, like this one.

In theory either can work, though my personal experience is that working with identical interchangeable objects can get pretty finicky, so I’d recommend the property route.

3 Likes

Hmm

Do you think this is practical? (If i handle each pile the player can find individually as i did the 32 Zorkmids and just put that in the chest)

[TESTING ZORKMIDS]
A Zorkmid is a kind of thing.

PlayerZorkmidBalance is a number that varies.
PlayerZorkmidBalance is 0.

a Balance of Zorkmids is a thing.
The printed name of a Balance of Zorkmids is "[if PlayerZorkmidBalance <= 2]a Zorkmid[otherwise] Zorkmids[end if]"

A Zorkmid is a kind of thing.
The Plural of Zorkmid is Zorkmids.

Understand "Zorkmids" as 32 Copper Zorkmids.

32 Copper Zorkmids is a Zorkmid. The description is "it is a pile of 32 Copper Zorkmids here."
The initial appearance of a Balance of 32 Copper Zorkmids is "You see a pile of Copper Zorkmids here."

Instead of taking 32 Copper Zorkmids:
	now PlayerZorkmidBalance is PlayerZorkmidBalance + 32;
	say "You now have a balance of: [PlayerZorkmidBalance]zm".
	now 32 Copper Zorkmids is nowhere.
	
the printed name of 32 Copper Zorkmids is "Pile of Zorkmids".
the indefinite article of 32 Copper Zorkmids is "a"

	
Zorkstack is a number that varies.

When play begins:
	if PlayerZorkmidBalance is greater than 0:
		now the player holds a Balance of Zorkmids.
		
Every turn when PlayerZorkmidBalance is greater than 0:
	now the player holds a Balance of Zorkmids.

Every turn when PlayerZorkmidBalance <= 0:
	remove a Balance of Zorkmids from play.
	
Instead of dropping a Balance of Zorkmids:
	say "There's no reason to leave valuable currency behind.";
	
Understand "Zorkmids" or "Zorkmid" or "Money" as a Balance of Zorkmids.

I know its not exactly using your advice but it sure did help me understand what I did not before

this way I’ve posted also fuses the idea from the topic you linked to help me create my inventory specification:

Rule for printing inventory details of Balance of Zorkmids:
	if PlayerZorkmidBalance <= 10:
		display figure of Zorkmids;
	otherwise:
		display figure of Zorkmidlots;
	say "You have a balance of: [PlayerZorkmidBalance]zm".

Yeah, this approach seems like it should work – there might be issues if the player tries something like “take 13 zorkmids” rather than the full amount, and “take all zorkmids” might lead to some odd behavior depending on how your various understand statements interact, but those should all be manageable issues.

2 Likes

A very incomplete version of a system that allows quantities of money to be put in any room, container, supporter or actor (inventory), and allows them to be split and combined in any fashion:

Lab is a room.

The desk is a supporter in the Lab.

The box is a container in the Lab.

A thing has a number called the zorkmid content.
A room has a number called the zorkmid content.

The zorkmid content of the Lab is 23.

quantity of zorkmids is a thing.
The printed name is "[zorkmid content of the quantity of zorkmids] Zm";

Before examining: 
	if the noun is a container:
		if the zorkmid content of the noun > 0:
			now the zorkmid content of the quantity of zorkmids is the zorkmid content of the noun;
			now the quantity of zorkmids is contained by the noun;
			
Before printing the locale description (this is the add zorkmids rule):
	if the zorkmid content of the location > 0:
		now the zorkmid content of the quantity of zorkmids is the zorkmid content of the location;
		now the quantity of zorkmids is in the location;

The add zorkmids rule is listed before the find notable locale objects rule in the before printing the locale description rules.
			
After examining:
	now the quantity of zorkmids is nowhere;
	continue the action;
			
Before printing room description details of a container (called the holder):
	if the zorkmid content of the holder > 0:
		now the zorkmid content of the quantity of zorkmids is the zorkmid content of the holder;
		now the quantity of zorkmids is contained by the holder;

[After printing room description details of a container:
	now the quantity of zorkmids is nowhere;]
	
The zorkmid content of the box is 5.

The zorkmid content of the player is 10;

Before taking inventory:
	if the zorkmid content of the player > 0:
		now the player carries the quantity of zorkmids;
		now the zorkmid content of the quantity of zorkmids is the zorkmid content of the player;

After taking inventory:
	now the quantity of zorkmids is nowhere;
	continue the action;
	
Appropriating is an action applying to one number. Understand "take [number] zm/zorkmids" as appropriating.

Check appropriating (this is the can't take too much money rule):
	if the zorkmid content of the location < the number understood:
		say "[There] [aren't] that much money here.";
		
Check appropriating (this is the can't take too little money rule):
	if the number understood is 0:
		say "[We] [can't] take no money at all.";
	otherwise if the number understood < 0:
		say "[We] [can't] take negative money!";
		
Carry out appropriating:
	now the zorkmid content of the location is the zorkmid content of the location minus the number understood;
	now the zorkmid content of the player is the zorkmid content of the player plus the number understood;

Report appropriating:
	say "[We] [are] [number understood] Zm richer!";
	
Test me with "i/x box/take 4 zorkmids/l/i".

Among those things which are not done: dropping; taking from/insert into containers/supporters; correct handling of actors; and probably lots of stuff I haven’t thought of.

Anyone know if there’s an extension that does this?

1 Like