Problem with overlay/menu button/displaying statistic

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
roankun
Regular
Posts: 94
Joined: Fri Jun 11, 2010 4:01 am
Projects: RHS
Contact:

Problem with overlay/menu button/displaying statistic

#1 Post by roankun » Thu May 12, 2011 2:44 pm

So my game is based on affection points. Those points can be viewed via a clicking a game menu button. The main problem is written below, but I felt that I had to write these first in order for you (my mentor XD) to fully understand what is wrong with me my work.

Here's my code for the affection points (the other details are cut from this)

Code: Select all

init:
    $ tn_love = 0
 
label start:
    $ tn_love = 0
Yes, I put it both in init and label start. I started a thread sometime ago and the people there suggested that I put those put NOT in init but in label start. However, when I do that, I get an error saying something like tn_love isn't defined or something, so I put it in both.

Next, for the game menu buttons and to show the affection points of guy1:

Code: Select all

init python:
    def button_game_menu():
        
        if show_button_game_menu:

            ccinc = renpy.curried_call_in_new_context

            ui.hbox(xpos=0.985, ypos=0.81, xanchor='right', yanchor='bottom')
            ui.textbutton("Skip", clicked=toggle_skipping, xminimum=80)
            ui.textbutton("Load", clicked=ccinc("_game_menu_load"), xminimum=80)
            ui.textbutton("Stat", clicked=ccinc("stat"), xminimum=80)
            ui.close()


    config.window_overlay_functions.append(button_game_menu)

    def tn_love():
        if tn_affect_show:
            ui.vbox(xpos=1, ypos=0)
            ui.text("Guy1: %s" %tn_love)
            ui.frame()
    config.overlay_functions.append(tn_love)
If you haven't noticed, my button for Stat (which is what you click to show the affection points isn't the same as the one for the affection points screen(?) of Guy1. That's because I haven't figured out how to do that yet. XD Considering I have 5 other guys to include, I'm still at a loss on how to do that.

Main Problem
Okay, the main problem here is that whenever I try to show the affection points of Guy1, in other words, when I include

Code: Select all

$ tn_affect_show = True
in the script (because like I said, I haven't rigged it so that that happens when I click the Stat button) here's what happens:
Before $ tn_affect_show
Image

After:
Image

For some reason, the frame, which should have been around Guy1= 0, is below that, and the game buttons moved to the top. I'm really at a loss. I don't know how to deal with this. X(

And then right after that, when I click for the next dialog to show, an error occurs.

Code: Select all

I'm sorry, but an uncaught exception occurred.

Exception: Widget <renpy.display.layout.Window object at 0x036DDD90> expects a child.

While running game code:
 - script at line 392 of F:\EJ\Programs\Renpy\Otomegokoro/game/script.rpy
I really really REALLY don't know what to do. Help.:(
I don't have any kind words to spare to someone who already has all the reason in the world to feel good about himself.
http://roankun.wordpress.com/

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Problem with overlay/menu button/displaying statistic

#2 Post by Aleema » Thu May 12, 2011 2:51 pm

You have a dangling ui.frame() at the end of your tn_love() overlay. It's most likely looking for a child, since all ui.frames() need 1 child. And it likely adopted the ui.hbox() of your stats. Remove that ui.frame() and see what happens. (Removing it should also solve your error.)

User avatar
roankun
Regular
Posts: 94
Joined: Fri Jun 11, 2010 4:01 am
Projects: RHS
Contact:

Re: Problem with overlay/menu button/displaying statistic

#3 Post by roankun » Thu May 12, 2011 11:28 pm

Thank you Aleema! I only noticed it now, but you're almost always the one who helps me! My hero *.*

Um, last question then. What if I do want a frame around it?
Nevermind, I just put it in an image background. :)
Again, thank you very very VERY much. :D
Last edited by roankun on Thu May 12, 2011 11:34 pm, edited 2 times in total.
I don't have any kind words to spare to someone who already has all the reason in the world to feel good about himself.
http://roankun.wordpress.com/

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Problem with overlay/menu button/displaying statistic

#4 Post by Aleema » Thu May 12, 2011 11:34 pm

ui.frame()s are put before their children:

Code: Select all

            ui.frame()
            ui.vbox(xpos=1, ypos=0)
            ui.text("Guy1: %s" %tn_love)
            ui.close()
In this case, the vbox is the child. I added a ui.close() at the bottom. You should always close the widgets that need to be closed (hbox/vbox, grid, etc).

But this is more efficient:

Code: Select all

            ui.frame(xpos=1, ypos=0)
            ui.text("Guy1: %s" %tn_love)

User avatar
roankun
Regular
Posts: 94
Joined: Fri Jun 11, 2010 4:01 am
Projects: RHS
Contact:

Re: Problem with overlay/menu button/displaying statistic

#5 Post by roankun » Thu May 12, 2011 11:36 pm

Oh, I see. This might be easier than making another image. XD Thank you!
I don't have any kind words to spare to someone who already has all the reason in the world to feel good about himself.
http://roankun.wordpress.com/

Post Reply

Who is online

Users browsing this forum: Google [Bot]