Can't seem to find a money system that works

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
JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Can't seem to find a money system that works

#1 Post by JaxxyLupei »

Hey, me again. This time with a new dilemma.
I want to have a money system in my game. I also want to incorporate it with the inventory system found here: http://lemmasoft.renai.us/forums/viewto ... 51&t=23071 I've tried the tutorial showcased on the wiki (using example 2) but I get errors like "money not defined" whenever I try to have money added throughout the script.

So I decided to search for a new one. I came across the one listed here: http://lemmasoft.renai.us/forums/viewto ... =8&t=26291

It's an easier code, but what I want is for the money to be on screen throughout most of the gameplay instead of just at the store. I've tried the $ showmoney = True from the one I linked, messed with the positioning but it doesn't show up. Is there a way to configure any of these codes to do this, or do I need a new code altogether? Or am I just messing something up? I'm a newbie to this still, so I have no idea what to do.

If anyone could help it would be greatly appreciated.

nintendotoad
Regular
Posts: 42
Joined: Sat Mar 31, 2012 2:56 pm
Location: projectexist.net
Contact:

Re: Can't seem to find a money system that works

#2 Post by nintendotoad »

Here's what I do:

Code: Select all

init -1:
    $ show_wallet = False
    $ main_char_cash = 0

init python:
    import locale
    locale.setlocale(locale.LC_ALL, 'en_US')

    def Wallet():
        ui.frame(xfill=False, xminimum = 125, yminimum=None, xalign=0.899, yalign = 0.76, style='clipFrame')
        #you'll need different xalign/yalign/style values
        ui.vbox()
        ui.text(locale.currency(main_char_cash), xalign=1.0, size=checkSizeTwo())
        #change checkSizeTwo() to some other number
        ui.close()
        return

screen say:
    if (show_wallet):
        $ Wallet()
    #remainder of say code truncated, but you can add this code to
    #other screens

label start:
    "Where in the name of whatever something or other did I put my wallet...?"
    $ show_wallet = True
    "All the bills and coins fell out, let me put them back in real fast."
    $ main_char_cash = 0123.456
    "Oh, I found it, but from looking on the screen, I will wrongly assume that I have $123.46 cents."
So what's going on?

* We initialize the variables we intend on using. (We start off by saying "no, we don't want to show the wallet when someone is saying something" and "we're broke yo".)
* We import the locale module, which is built-in.
* We demand the English - United States locale so that locale.currency throws on the right currency symbol. It doesn't have to be en_US but it needs to be something if you plan on releasing OSX versions of your game. (Why?)
* We write a Python function that draws our frame.
* In particular, we check for show_wallet in any screen that is "willing" to display the wallet.
* I looked through the code in the linked example. It does seem that it was not shown that the given money function had to actually be called by something. Simply calling display_money() in a few screens should get the code to do what you want, but I provided my stuff for kicks.
* You can of course, also move the if(show_wallet) statement from the screen to the actual Python function as is done in the example.

JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Re: Can't seem to find a money system that works

#3 Post by JaxxyLupei »

I've placed the code into my script, however, I get an error saying that the locale is unsupported:

While executing init code:
File "game/script.rpy", line 43, in script
init python:
File "game/script.rpy", line 45, in <module>
locale.setlocale(locale.LC_ALL, 'en_US')
Error: unsupported locale setting

I guess it isn't built-in for mine?

User avatar
Zetsubou
Miko-Class Veteran
Posts: 522
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: Can't seem to find a money system that works

#4 Post by Zetsubou »

JaxxyLupei wrote:I've placed the code into my script, however, I get an error saying that the locale is unsupported:
I guess it isn't built-in for mine?
What country are you in? What's the default locate for your operating system?
It sounds like you don't have the en_US locale installed. You can either install it, or use your own locale (eg. en_GB, en_AU, etc).
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure, An Adventurer's Gallantry
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails

Working on:
Sable's Grimoire 2

https://zetsubou.games

nintendotoad
Regular
Posts: 42
Joined: Sat Mar 31, 2012 2:56 pm
Location: projectexist.net
Contact:

Re: Can't seem to find a money system that works

#5 Post by nintendotoad »

You can use the below code and then knock-out the locale lines. The lack of en_US is somewhat concerning, however.

Code: Select all

    def Wallet():
        ui.frame(xfill=False, xminimum = 125, yminimum=None, xalign=0.899, yalign = 0.76, style='clipFrame')
        ui.vbox()
        ui.text("$%.2f" % main_char_cash, xalign=1.0, size=checkSizeTwo())
        ui.close()
        return

JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Re: Can't seem to find a money system that works

#6 Post by JaxxyLupei »

I'm in America, so I'm not sure as to why it's not working for me. I tried the fixed code, only now it's telling me this:

Code: Select all

  File "game/commonScenes.rpy", line 8, in script
    t "Hi there! My name is Thea Campbell! But you can call me, Thea. I'm here to give you the basics of how to navigate through this game. First, in order to go through the game, you press your spacebar or click your left mouse button."
Exception: The say screen (or show_function) must return a Text object.
This is the first spoken line in the game (obviously) is there a way to install the locale as Zetsubou suggested?

nintendotoad
Regular
Posts: 42
Joined: Sat Mar 31, 2012 2:56 pm
Location: projectexist.net
Contact:

Re: Can't seem to find a money system that works

#7 Post by nintendotoad »

Not in a way that is user-friendly. My guess is that the code is 'en_US' for UNIX/Mac systems, and 'English' for Windows systems. So you could do:

Code: Select all

            if sys.platform == "win32":
                locale.setlocale(locale.LC_ALL, 'English')
                #aka English_United States.1252
            else:
                locale.setlocale(locale.LC_ALL, 'en_US")
However, even if you do that, you'll still have the same error message in screen say. This is because screen say has to be "full". If you use only use that screen say code, you will run into problems up the ***; my guess is that you re-defined screen say entirely rather than just add a few lines of code. In other words, you need to change the definition in screens.rpy, and not making a new definition.

Code: Select all

screen say:
    if(show_wallet):#this is a new line
         $ Wallet()# this is a new line
    #Everything below this line should already be in screens.rpy
    # Defaults for side_image and two_window
    default side_image = None
    default two_window = True
    # Decide if we want to use the one-window or two-window varaint.
    if not two_window:
        # The one window variant.        
        window:
            id "window"
            has vbox:
                style "say_vbox"
            if who:
                text who id "who"
            text what id "what"
    else:
        # The two window variant.
        vbox:
            style "say_two_window_vbox"
            if who:            
                window:
                    style "say_who_window"
                    text who:
                        id "who"
            window:
                id "window"
                has vbox:
                    style "say_vbox"
                text what id "what"
    # If there's a side image, display it above the text.
    if side_image:
        add side_image
    else:
        add SideImage() xalign 0.0 yalign 1.0

    # Use the quick menu.
    use quick_menu
^ You need to make screen say in screens.rpy look like that.

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]