Money??? please give advice

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Guest

Money??? please give advice

#1 Post by Guest » Thu Aug 09, 2007 12:43 am

I am working on a game wherein I'd like there to be a money system of some sort. I can see how I could use variables as money (and add or subtract it as needed), but how could I show the value of the variables to the player? Are there other ways to have money in a game? Any advice would be appreciated.

User avatar
DaFool
Lemma-Class Veteran
Posts: 4171
Joined: Tue Aug 01, 2006 12:39 pm
Contact:

Re: Money??? please give advice

#2 Post by DaFool » Thu Aug 09, 2007 9:34 am

Taken directly from my own game:

Code: Select all

label purchasemiller:
    menu:
        "Buy Pork (50 Gold)":
            if (gold >= 50):
                play sound("change.ogg")
                kneutral "Some ham and sausages please."
                miller "Here you go."
                $ yieldpork += 1
                $ gold -= 50
            else:
                kneutral "Oh, I do not have enough money anymore for this item."
            jump purchasemiller
        "Buy Bread (20 Gold)":
            if (gold >=20):
                play sound("change.ogg")
                kneutral "Some bread please."
                miller "Right away, madam."
                $ yieldbread += 1
                $ gold -= 20
            else:
                kneutral "Oh, I do not have enough money anymore for this item."
            jump purchasemiller
        "Buy Cheese (35 Gold)":
            if (gold >= 35):
                play sound("change.ogg")
                kneutral "I would like some cheese."
                miller "Very well."
                $ yieldcheese += 1
                $ gold -=35
            else:
                kneutral "Oh, I do not have enough money anymore for this item."
            jump purchasemiller
        "Check Wallet.":
            kneutral "It looks like I have %(gold)d Gold."
            jump purchasemiller
        "Stop Purchasing.":
            ksmile "I better leave now before I run out of money."
    return
Note the line which outputs the value of gold: "%(gold)d"

Ideally, you would have an inventory system also, but I'm not at a level where I'm willing make one.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Money??? please give advice

#3 Post by Showsni » Thu Aug 09, 2007 4:58 pm

Do you mean you want the amount of money constantly shown, at the top or something? (Like, say, Zelda.)

Guest

Re: Money??? please give advice

#4 Post by Guest » Thu Aug 09, 2007 5:24 pm

This isn't the same guest that asked the question, but I would like to know how to get the total money up at the top. I tried "%(gold)d" in an ui.frame at the top, but it doesn't show the amount, it just shows "%(gold)d."

User avatar
J13
Regular
Posts: 60
Joined: Wed Jan 24, 2007 3:28 am
Location: Cambridge
Contact:

Re: Money??? please give advice

#5 Post by J13 » Thu Aug 09, 2007 8:15 pm

I don't know if this is what you're looking for, i'm using it for an in game clock in the game i'm working on, but this is what it'd look like if i wanted to do the same for money

Code: Select all

init:
    $ text = 'MONEY' 
    $ curren = '$'
    $ money = 537

init python:
    show_money = True
    def stats_overlay():
        if not show_money:
            return
        stats_frame('Time', xalign=1.0, yalign=0.0)        
    config.overlay_functions.append(stats_overlay) 
    def stats_frame(name, **properties):
        ui.frame(xfill=False, yminimum=None, **properties)
        ui.hbox()
        ui.vbox()
        ui.text('%s' % (text), xalign=0.0, size=20) 
        ui.text('%s%02d' % (curren,money), xalign=0.0, size=25) 
        ui.close()
        ui.close()

label start:
    'Start'
    $ money += 20    
    'Adding more money'
    $ show_money = False
    'Making the money displayable dissapear'
    $ show_money = True
    'And reappear'
    'End'
Hope that helps some

User avatar
Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: Money??? please give advice

#6 Post by Criptych » Thu Aug 09, 2007 9:34 pm

Guest wrote:This isn't the same guest that asked the question, but I would like to know how to get the total money up at the top. I tried "%(gold)d" in an ui.frame at the top, but it doesn't show the amount, it just shows "%(gold)d."
That's because python statements don't automatically interpolate variables. Note in J13's code:

Code: Select all

        ui.text('%s%02d' % (curren,money), xalign=0.0, size=25)
The "% (curren, money)" clause inserts the values into the string.
Computers are useless. They can only give you answers. —Pablo Picasso

Image

Guest

Re: Money??? please give advice

#7 Post by Guest » Thu Aug 09, 2007 9:59 pm

This is the original guest, heh.

Thank you so much for your advice! I'm implementing the scripts right now. I really appreciate your help!! <3

themocaw
Regular
Posts: 106
Joined: Mon Aug 06, 2007 10:58 am
Contact:

Re: Money??? please give advice

#8 Post by themocaw » Fri Aug 10, 2007 12:35 pm

That's actually really great. I'm planning on using a temporary script like this as a debug tool for keeping track of the major emotional variables: I know there's probably some developer tool that lets us do that, but this feels more elegant.

User avatar
Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: Money??? please give advice

#9 Post by Criptych » Fri Aug 10, 2007 3:48 pm

themocaw wrote:That's actually really great. I'm planning on using a temporary script like this as a debug tool for keeping track of the major emotional variables: I know there's probably some developer tool that lets us do that, but this feels more elegant.
Why make it "temporary"? That could be the developer tool. 8)
Computers are useless. They can only give you answers. —Pablo Picasso

Image

themocaw
Regular
Posts: 106
Joined: Mon Aug 06, 2007 10:58 am
Contact:

Re: Money??? please give advice

#10 Post by themocaw » Fri Aug 10, 2007 3:56 pm

Criptych wrote:
themocaw wrote:That's actually really great. I'm planning on using a temporary script like this as a debug tool for keeping track of the major emotional variables: I know there's probably some developer tool that lets us do that, but this feels more elegant.
Why make it "temporary"? That could be the developer tool. 8)
I mean temporary as in, "Damned if I'm going to let the script stay in there for the final distribution, you young punks". Although, it might make a nice unlockable. Hmmm. . .

User avatar
Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: Money??? please give advice

#11 Post by Criptych » Fri Aug 10, 2007 4:09 pm

themocaw wrote:I mean temporary as in, "Damned if I'm going to let the script stay in there for the final distribution, you young punks".
:lol: Point taken.
Computers are useless. They can only give you answers. —Pablo Picasso

Image

User avatar
Free Time Machine
Regular
Posts: 42
Joined: Fri Jun 15, 2007 9:45 am
Location: Philly, USA
Contact:

Re: Money??? please give advice

#12 Post by Free Time Machine » Sun Aug 12, 2007 5:31 pm

Hey, this is awesome as a debug tool. I tried a similar thing debugging with a ui bar, but I feel a digit value is much more useful for any game with hidden stats. Let me suggest the following changes/comments to the first init block to make it easier for new people to get...

Code: Select all

init:
    $ statlabel = 'STRING'
    # Replace 'STRING' with an appropriate label for the statistic, eg 'MONEY'
    $ statprefix = 'STRING'
    # Replace 'STRING' with an appropriate prefix for the statistic, eg '$' or '' for none
    $ statvalue = 0
"HOLD ON TIGHT" ~ Outfits and expressions, where art thou? And why does Elsa's face look so awful??? *bangs head in*

Everytime you delete a traceback, someone else gets it. -PyTom

themocaw
Regular
Posts: 106
Joined: Mon Aug 06, 2007 10:58 am
Contact:

Re: Money??? please give advice

#13 Post by themocaw » Sun Aug 12, 2007 8:13 pm

Image

This works EXTREMELY well.

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Money??? please give advice

#14 Post by UselessCoder » Sat Mar 05, 2016 7:03 am

Hi everybody!

I've found this topic while trying to tweak my money displayable.

I think that part of this code might as well work for me, but I'm so new to renpy I might be wrong. wthout a doubt my coding is, since it doesn't work anyway. :lol:

Let me first tell you how my money variable works, it's pretty basic:

in scripts.rpy:

Code: Select all

init:
   $ money = 99999
label start:
    show screen money
in screens.rpy

Code: Select all

screen money:
    imagebutton: # MONEY.
        xpos 1230
        ypos 39
        focus_mask None 
        xanchor "center"
        yanchor "center"
        idle "icons/money.png"    
    hbox:
        spacing 10 xpos 1150 ypos 25        
        text "{color=#FFFFFF}{size=-3} $ [money]{/size}{/color}"
Now. What I tried to do was adding the variables:

Code: Select all

   $ thousands= 'K'
   $ millions= 'M'
to the script file because, for the displaying sake, I want the total amount of money to be as readable as possibile as it grows bigger and I don't want ridicolously huge amounts of money spanning from one side of my screen to the other.

So what I tried to do was using something like this:

Code: Select all

('%s%02d' % (money, thousands)
('%s%02d' % (money, millions)
but I can't trigger them through something like:

Code: Select all

if (money > 99999)
if (money > 999999)

..."Then put thousand at the end of the amount" or "Then put millions at the end of the amount" , accordingly.

What should I do?

Thanks!

User avatar
gas
Miko-Class Veteran
Posts: 535
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Money??? please give advice

#15 Post by gas » Sat Mar 05, 2016 12:25 pm

You already created a topic for that.
10 ? "RENPY"
20 GOTO 10

RUN

Post Reply

Who is online

Users browsing this forum: No registered users