Negative Money :(

No problem. :slight_smile:

Hmmm… Maybe change things around a bit so edibles have a number called stock. I’m specifically using the candy bar here, but you could have a kind of liquid called Potion and do it that way for multiple potions. As you can see, I’ve slimmed this down to a “candy bar only vending machine” to try to keep the example clearer.

Basically, we’re intercepting things to keep the player always with a candy bar with at least a stock of 0. We only allow eating, dropping, other things when the stock is over 0. We increment when buying, decrement when eating or dropping, we stop attempts to give away our precious 3,000 year old candy bar :wink:

There are probably more elegant ways to handle this, but it seems to work. You’ll need to add some spit and polish:

The store is a room.

Percy is a man in the store.

Price is a kind of value. $10.99 specifies a price with parts dollars and cents (optional, preamble optional).

A person has a price called wealth. The wealth of the player is $15.

A thing has a price. The price of a thing is usually $5.00.

Buying it from is an action applying to two things. Understand "buy [something] from [something]" as buying it from.

Vending machine is an unopenable container in the store.

A candy bar is an edible thing. The player carries a candy bar. The price of the candy bar is $1.50.
A candy bar has a number called stock. The stock is usually 0.

Rule for printing inventory details of a candy bar:
	say "(x[stock of the candy bar])".

Before doing anything with a candy bar when the stock of a candy bar is 0:
	if trying buying a candy bar from a vending machine:
		continue the action;
	else:
		say "You don't have one";
		stop the action.

Instead of dropping a candy bar:
	say "You drop a candy bar. A vermin of some sort runs off with it.";
	decrement the stock of the candy bar.
	
Instead of giving a candy bar to someone:
	say "No, that's yours.".	

Instead of eating a candy bar:
	say "It would be delicious, if it weren't 3,000 years old...";
	say "Your health goes up by 5 points!";
	decrement the stock of the candy bar.

Carry out buying it from:
	if the wealth of the player is greater than the price of the noun:
		decrease the wealth of the player by the price;
		if the player does not have the noun:
			move the noun to the player;
		else:
			increment the stock of the noun;
		say "You bought [the noun].";
	else:
		say "You can't buy that! The price is [price of the noun] and you only have [wealth of the player]!";
		stop the action.

After taking inventory, say "You have [the wealth of the player]."

When play begins: now right hand status line is "Cash: [wealth of the player]".

Example output:

store
You can see Percy and Vending machine (empty) here.

>buy candy bar from vending machine
You bought the candy bar.

>buy candy bar from vending machine
You bought the candy bar.

>buy candy bar from vending machine
You bought the candy bar.

>buy candy bar from vending machine
You bought the candy bar.

>i
You are carrying:
  a candy bar(x4)

You have $9.

>drop candy bar
You drop a candy bar. A vermin of some sort runs off with it.

>drop candy bar
You drop a candy bar. A vermin of some sort runs off with it.

>drop candy bar
You drop a candy bar. A vermin of some sort runs off with it.

>drop candy bar
You drop a candy bar. A vermin of some sort runs off with it.

>drop candy bar
You don't have one
>drop candy bar
You don't have one
>i
You are carrying:
  a candy bar(x0)

You have $9.

>buy candy bar from vending machine
You bought the candy bar.

>eat candy bar
It would be delicious, if it weren't 3,000 years old...
Your health goes up by 5 points!

>i
You are carrying:
  a candy bar(x0)

You have $7.50.

>buy candy bar from vending machine
You bought the candy bar.

>give candy bar to percy
No, that's yours.

Oooh thanks! That’ll work nicely. I was thinking that I had to do a machine that has just only one item, actually. I’ll pull something off like this. You’re great, man! This is really helping my game! With some of the cool code I came up with, you’d think I would have figured this one out. Awesome. My game’s gonna be great!

Glad to help :slight_smile:

Feel free to shine a little light my way in the credits, if you feel like it :slight_smile:

I will!!

Thanks :slight_smile: I appreciate the egoboo. :slight_smile: