Hiding a Stat Screen

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
User avatar
Sumoslap
Regular
Posts: 59
Joined: Tue Oct 12, 2010 10:02 pm
Contact:

Hiding a Stat Screen

#1 Post by Sumoslap »

Hi all:

As I said in my first post, I am not a programmer at all, but Ren'Py and the community here are so user-friendly that I am on the brink of having the coding framework done for my modest game. I am stuck now, though, and would be most grateful for a little help. Apologies in advance for coding stupidity, as I am sure this is a super-easy problem to fix for even a beginning programmer.

I am trying to create a Stat screen overlay in the top-left corner that can be hidden. When it is hidden, a single image ("Show Stats") appears in the top left; clicking on it show the stat overlay once again.

I have had most parts of it working this morning: the overlay appears, images and bars and all, and is populated with the correct stats. But when I tried to create the "Hide Stats" and "Show Stats" funtionality, nothing at all appears now, as if the overlay isn't called to begin with.

Here is all of what I think is the relevant code:

Code: Select all

init:
    $ maxpassion = 100
    $ maxeloquence = 100
    $ maxintelligence = 100
    $ startpassion = 60
    $ starteloquence = 5
    $ startintelligence = 85
    python:               
        def stats_visible():
            #if not show_stats: <--I commented these out, thinking that the function was covered below. Didn't work when it was commented in, anyway
                #return
            if not show_stats:
                ui.frame(xfill=False, yminimum=None, xalign=0.0, yalign=0.0)
                ui.vbox()
                ui.at(Position(xpos=10, ypos=10, xanchor='left', yanchor='top'))
                ui.imagebutton("showstats.png", "showstats.png", clicked=ui.returns("showstats"))
                ui.close()
                
                result = ui.interact() # The "$" returned an error here, so I took it out. The code ran, but nothing appeared
                
                if result == "showstats":
                    show_stats = True # The "$" returned an error here too, so I took it out. The code ran, but nothing appeared
                    return  
                    
                return
            if show_stats:
                ui.frame(xfill=False, yminimum=None, xalign=0.0, yalign=0.0)
                ui.vbox()
                ui.at(Position(xpos=10, ypos=10, xanchor='left', yanchor='top'))
                #ui.text("Passion", size=24)
                ui.image("passionbutton.png")
                ui.bar(range=maxpassion,value=startpassion,style="bar",xmaximum=150)
                ui.at(Position(xpos=10, ypos=10, xanchor='left', yanchor='top'))
                #ui.text("Eloquence", size=24)
                ui.image("eloquencebutton.png")
                ui.bar(range=maxeloquence,value=starteloquence,style="bar",xmaximum=150)
                ui.at(Position(xpos=10, ypos=10, xanchor='left', yanchor='top'))
                #ui.text("Intelligence", size=24)
                ui.image("intelligencebutton.png")
                ui.bar(range=maxintelligence,value=startintelligence,style="bar",xmaximum=150)
                ui.imagebutton("hidestats.png", "hidestats.png", clicked=ui.returns("hidestats"))
                
                ui.close ()
                
                result = ui.interact()
                
                if result == "hidestats":
                    show_stats = False
                    return   

    $ show_stats = False

#...

label start:
    stop sound
    scene black
    pause (.5)
    show feelinGroovy at Position(xpos = 0.5, xanchor=0.5, ypos=0.35, yanchor=0.5) with slowdissolve 
    $ renpy.pause(1)
    hide feelinGroovy with slowdissolve
    $ renpy.pause(1)
    g "Hello, little light! Welcome to life!"
    g "We have a lot of work to do, little light. But let's start at the beginning."
    g "It's time for you to give yourself a name."
    $ attemptanswer = "" 
    $ yname = renpy.input("What is your name?") or "Dulcimer"
    y "Let it be so. Henceforth, I shall be known as %(yname)s."
    scene library with slowdissolve
    "Testing to see how the narrator's text looks."
    g "You are trying to help Orlando. Here are his stats."
    $ show_stats  = True
    "The stat bar should have appeared if the code is working correctly."
    
    return
Please excuse the bad placeholder writing! :oops: Any/all help much appreciated.

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: Hiding a Stat Screen

#2 Post by LordShiranai »

You may be better off in 6.11 defining a custom screen versus using overlays. In many cases, screens will be easier to use.

Let me see if I can do a small example real quick.
Don't Blame Me. I Voted for Vermin Supreme.

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: Hiding a Stat Screen

#3 Post by LordShiranai »

Okay, here is a very basic stat box that defines a custom screen in Python which does the basics of what you want. There may be a "better" way to do this, mind you, but this is pretty quick and dirty.

The following is a screen defined with Python code, as well as a helper function which will toggle show_stats and then restart the interaction.

Code: Select all

init python:
    def stat_box(**kwargs):
        curried_toggle = renpy.curry(toggle_stats)
        if show_stats:
            ui.frame()
            ui.vbox()
            ui.text("Stat 1: %d" % stat_1)
            ui.text("Stat 2: %d" % stat_2)
            ui.textbutton("Hide Stats", clicked=curried_toggle(False))
            ui.close()
        else:
            ui.frame()
            ui.textbutton("Show Stats", clicked=curried_toggle(True))
    renpy.define_screen("stat_box", stat_box)

    def toggle_stats(x):
        global show_stats 
        show_stats = x
        renpy.restart_interaction()
The following initializes the two stats variables and the show_stats value.

Code: Select all

label start:

    python:
        stat_1 = 4
        stat_2 = 5
        show_stats = False
    
    show screen stat_box

    "Blah blah blah."
So basically when you run this, you'll start out with a button which will allow you to show stats. Then when you click it, it'll show the stats along with a button that allows you to hide them.
Don't Blame Me. I Voted for Vermin Supreme.

User avatar
Sumoslap
Regular
Posts: 59
Joined: Tue Oct 12, 2010 10:02 pm
Contact:

Re: Hiding a Stat Screen

#4 Post by Sumoslap »

Thanks a million, LordShiranai. This is well beyond my skills, so I greatly appreciate you taking the time to write code I can steal. Going to try implementing right now!

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: Hiding a Stat Screen

#5 Post by LordShiranai »

No problem. Hope that it works for you.
Don't Blame Me. I Voted for Vermin Supreme.

User avatar
Sumoslap
Regular
Posts: 59
Joined: Tue Oct 12, 2010 10:02 pm
Contact:

Re: Hiding a Stat Screen

#6 Post by Sumoslap »

15 minutes later, I have a working system, LordShiranai. I am adding you to the "Special Thanks" credits of my game. Also, I might suggest that your post be added to the Cookbook: it's easy to copy into code, perfectly functional, and simple even for a newb-o like me to customize (I replaced the text with images and stats with bars).

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: Hiding a Stat Screen

#7 Post by LordShiranai »

Sumoslap wrote:15 minutes later, I have a working system, LordShiranai. I am adding you to the "Special Thanks" credits of my game. Also, I might suggest that your post be added to the Cookbook: it's easy to copy into code, perfectly functional, and simple even for a newb-o like me to customize (I replaced the text with images and stats with bars).
Glad that it was of some use to you.

As far as adding stuff to the cookbook, I know that the Ren'Py site is due for a revamp, so I wasn't planning on contributing possible cookbook recipes until that point.
Don't Blame Me. I Voted for Vermin Supreme.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Hiding a Stat Screen

#8 Post by PyTom »

I don't think we're going to touch the cookbook - although I might do a pass to remove obsolete code.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Sabotank
Newbie
Posts: 3
Joined: Mon Jun 01, 2015 5:05 am
Contact:

Re: Hiding a Stat Screen

#9 Post by Sabotank »

How can I make, instead of number, a bar appear?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Hiding a Stat Screen

#10 Post by trooper6 »

A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Kamos
Regular
Posts: 33
Joined: Mon Jan 02, 2017 5:18 am
Tumblr: Kamos
Contact:

Re: Hiding a Stat Screen

#11 Post by Kamos »

It work amazing good job...
Last edited by Kamos on Sun Jul 16, 2017 3:42 pm, edited 1 time in total.

Kamos
Regular
Posts: 33
Joined: Mon Jan 02, 2017 5:18 am
Tumblr: Kamos
Contact:

Re: Hiding a Stat Screen

#12 Post by Kamos »

can anyone help me??? this look amazing but yesterday i change some lines and now screen show only when something is active - menu or talk.... what can I f..... up???

Post Reply

Who is online

Users browsing this forum: No registered users