intfiction.org

The Interactive Fiction Community Forum
It is currently Thu Dec 13, 2018 9:23 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Negative Money :(
PostPosted: Wed Sep 26, 2018 10:21 am 
Offline

Joined: Wed Sep 26, 2018 10:10 am
Posts: 12
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?


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Wed Sep 26, 2018 10:56 pm 
Online
User avatar

Joined: Sun May 21, 2017 4:59 pm
Posts: 302
Location: Michigan
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?

_________________
~~~
My ebooks on Amazon
My ebooks on Smashwords


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Wed Sep 26, 2018 11:37 pm 
Offline

Joined: Wed Sep 26, 2018 10:10 am
Posts: 12
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."


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Thu Sep 27, 2018 12:19 am 
Online
User avatar

Joined: Sun May 21, 2017 4:59 pm
Posts: 302
Location: Michigan
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:

Code:
"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:

Code:
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!

_________________
~~~
My ebooks on Amazon
My ebooks on Smashwords


Last edited by howtophil on Thu Sep 27, 2018 12:30 am, edited 2 times in total.

Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Thu Sep 27, 2018 12:22 am 
Online
User avatar

Joined: Sun May 21, 2017 4:59 pm
Posts: 302
Location: Michigan
Oh, (and I've fixed this in the code above) you need to change your reporting bit:

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

_________________
~~~
My ebooks on Amazon
My ebooks on Smashwords


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Thu Sep 27, 2018 12:23 am 
Offline

Joined: Wed Sep 26, 2018 10:10 am
Posts: 12
Thank you!!!!!!!! Yes, thank you!


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Thu Sep 27, 2018 12:25 am 
Online
User avatar

Joined: Sun May 21, 2017 4:59 pm
Posts: 302
Location: Michigan
CrazyFlitz wrote:
Thank you!!!!!!!! Yes, thank you!


No problem :)

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.

_________________
~~~
My ebooks on Amazon
My ebooks on Smashwords


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Thu Sep 27, 2018 12:30 am 
Offline

Joined: Wed Sep 26, 2018 10:10 am
Posts: 12
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.


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Thu Sep 27, 2018 12:31 am 
Online
User avatar

Joined: Sun May 21, 2017 4:59 pm
Posts: 302
Location: Michigan
Hmmm... Looking at it, you probably need a report more like this:

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

_________________
~~~
My ebooks on Amazon
My ebooks on Smashwords


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: Negative Money :(
PostPosted: Thu Sep 27, 2018 12:32 am 
Online
User avatar

Joined: Sun May 21, 2017 4:59 pm
Posts: 302
Location: Michigan
CrazyFlitz wrote:
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.


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

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

_________________
~~~
My ebooks on Amazon
My ebooks on Smashwords


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group