Negative Money :(


#1

I wouldn’t exactly call myself “new” to this program as I have been using it for a little while, but I have seemed to run into some trouble. I am using your regular currency code (on my other computer, so can’t put it here, but it’s easy enough to find online). I’m running into a negative money issue. I don’t want this to happen because then my character will have no reason to loot enemies or search for hidden treasure or the like. They’ll just stay in the negative because hey, why not? It’s not hurting them, right? How would I get rid of this? Also, I developed a simple fishing code that I can post later on. Where would I be able to post that?


#2

Hmmm… You’re in the “Getting Started Playing IF” section of the board right now, but it sounds like you’re asking a coding question.

Is this Inform 6/7 you’re asking about? Tads? Twine? Some other development system?


#3

I am using Inform7. But here is some of the code I am using that might help you.

Book - Money

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.

Carry out buying it from:
decrease the wealth of the player by the price;
move the noun to the player.

Report buying something (this is the buying rule):
say “You bought [the noun].”

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]”.

Section - Sell

Understand “sell [something]” as selling. Selling is an action applying to one thing.

Selling it to is an action applying to two things. Understand “sell [something] to [something]” as selling it to.

Report selling something (this is the first selling rule):
say “Who do you want to sell [the noun] to?”.

Instead of pushing the red button:
if a sea salt potion (called the salt) is in the ocean dispenser:
move the salt to the player;
decrease the wealth of the player by $5;
say “You got the sea salt potion.”;
stop the action;
otherwise:
say “There are none left.”


#4

I took out a bit to focus on what you need to add. Basically, you need an if and else in the “Carry out buying it from” section:

"Testing" by "Phillip J Rhoades".
The story headline is "Testing".
The story genre is "Test Code".
The release number is 1.
The story description is "A testbed of code".
The story creation year is 2018.

The store is a room.

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 a transparent unopenable container in the store.

A candy bar is an edible thing in the vending machine. The price of the candy bar is $5.50.
Some chips is an edible thing in the vending machine. The price of the chips is $10.00.
Some cookies is an edible thing in the vending machine. The price of the cookies is $20.00.

[Hooo Boy! Those are some expensive snacks!]

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;
		move the noun to the player;
	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.

Report buying it from (this is the buying rule):
	if the wealth of the player is greater than the price of the noun:
		say "You bought [the noun].".

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]".

This gets you output like this:

store
You can see Vending machine (in which are Candy bar, Chips and Cookies) here.

>buy cookies from vending machine
You can't buy that! The price is $20 and you only have $15!

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

>buy chips from vending machine
You can't buy that! The price is $10 and you only have $9.50!

#5

Oh, (and I’ve fixed this in the code above) you need to change your reporting bit:

Report buying it from (this is the buying rule):
	say "You bought [the noun].".

#6

Thank you!!! Yes, thank you!


#7

No problem :slight_smile:

Also, check the above first code I posted again really quick. I made a couple edits to make it work smoother. Removed a line from the “Carry out” and, of course, fixed the “report” bit too.


#8

Okay, cool. And this will work with normal NPC vendors too, right? It’s much too late for me to try it out tonight, but I’ll plug it in tomorrow.


#9

Hmmm… Looking at it, you probably need a report more like this:

Report buying it from (this is the buying rule):
	if the wealth of the player is greater than the price of the noun:
		say "You bought [the noun].".

#10

If you want to restrict it to buying from people, you might want to go with something like this:

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

#11

Ouch… Because the machines are the only way I know how to make multiple copies of potions. Everything else just gives me one item. No matter how many times I get the same item. So I’d love to buy from both. Though, I could have the vendors set up machines! I just might do that. Yeah, that’s probably the best action. :slight_smile: Okay, thanks a lot! You’ve been a great help!


#12

Here’s how it would look restricted to people only as sellers. (I also feel like the reporting bit is adding unnecessary complexity in this case, so I mashed it into the Carry out):

The store is a room.

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 [someone]" as buying it from.

Vending machine is a transparent unopenable container in the store.

Percy is a man in the store. He carries the watch. 

The price of the watch is $10.00.

A candy bar is an edible thing in the vending machine. The price of the candy bar is $5.50.
Some chips is an edible thing in the vending machine. The price of the chips is $10.00.
Some cookies is an edible thing in the vending machine. The price of the cookies is $20.00.

[Hooo Boy! Those are some expensive snacks!]

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;
		move the noun to the player;
		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 Vending machine (in which are a candy bar, some chips and some cookies) and Percy here.

>buy candy bar from vending machine
You can only do that to something animate.

>buy the watch from percy
You bought the watch.

>i
You are carrying:
  a watch

You have $5.

#13

Ha! Saw this after my last post. :slight_smile:

You’re welcome :slight_smile:


#14

Hey howtophil (and others), I’ve been meaning to ask somebody about this. Your code above, seems to be equivalent to the code below. It seems like I have often seen this kind of checking done both ways. Am I missing a subtle difference? From a compiler perspective, is one approach preferred over the other? Is one approach better in some circumstances but not others? (When?) etc…

[code]Check buying it from:
if the wealth of the player less than the price of the noun:
say “You can’t buy that! The price is [price of the noun] and you only have [wealth of the player]!” instead.

Carry out buying it from:
decrease the wealth of the player by the price of the noun;
move the noun to the player.[/code]


#15

Well, they can help keep things separate conceptually. There’s also a matter of which “comes first” during execution.

I tend to use “Check” only in cases with a large number of things that might stop the action, but I’m sure others use it every time.

inform7.com/learn/man/WI_12_9.html


#16

I’d say it’s “mostly stylistic” but I’m relatively new to inform 7, so Zarf or Hanon or someone might have a “more mature” view on the subject.


(Andrew Plotkin) #17

My experienced view is that it’s mostly stylistic. :slight_smile:


#18

Well, I’ll take that as confirmation of my viewpoint :smiley:


#19

Alrighty then. I guess that settles it. Thank you.


#20

I used your code and it worked perfectly, so thank you very much. The problem is, I can still only buy one of each item. Like, if I wanted more than one health potion, I can’t do it. Tried combining the original code where it gave me multiple copies of the same item with this code, and it didn’t work. Any suggestions?