[Solved] Trouble with Money Overlay

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
renpyuseranon
Newbie
Posts: 11
Joined: Wed Dec 05, 2018 4:25 pm
Contact:

[Solved] Trouble with Money Overlay

#1 Post by renpyuseranon »

I'm copying several snippets of code from this thread viewtopic.php?t=5373 into my own project and trying to get it to work. It's for an overlay that displays your current money, and can be hidden/shown when necessary. My code reads:

Code: Select all

init python:
    show_lion_cash = False

    def show_money_overlay():
        if show_lion_cash:
            cash_widget = Text( str(lioncash) );
            ui.at( Position(xalign=.9, yalign=.9) );
            ui.add(cash_widget);

    config.overlay_functions.append(show_money_overlay);

    def show_money():
        show_lion_cash = True;

    def hide_money():
        show_lion_cash = False;
Later on I test it with this:

Code: Select all

    $ lioncash = 100

    $ show_money()
    "Cash is shown."
    $ hide_money()
    "Cash is hidden."
In game, nothing happens. There's no error message, but the currency doesn't appear either. I've reread the code multiple times and can't figure out why it's not working. One thing of note - the thread I'm using is from 2009: could it be possible that the code has become obsolete over time?
Last edited by renpyuseranon on Sun Dec 09, 2018 11:38 am, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Trouble with Money Overlay

#2 Post by Alex »

Try to use screens - they were made to show stuff in more convinient way.

Code: Select all

default lioncash = 100

screen money_scr():
    text "[lioncash]" size 35 align (0.9, 0.9)

label start:
    scene black
    show screen money_scr
    "..."
    $ lioncash  += 50
    "Hey, what do we got here?.."
    hide screen money_scr
    "Better not to show vallet here..."
    "?"
https://www.renpy.org/doc/html/index.html
https://www.renpy.org/doc/html/screens.html
Last edited by Alex on Sun Dec 09, 2018 2:50 pm, edited 1 time in total.

renpyuseranon
Newbie
Posts: 11
Joined: Wed Dec 05, 2018 4:25 pm
Contact:

Re: Trouble with Money Overlay

#3 Post by renpyuseranon »

Damn, I just learned all about screens and yet it didn't occur to me to use one for this. Thanks man, that's super clean and simple.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]