Buttons on the text box/hud (SOLVED)

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
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Buttons on the text box/hud (SOLVED)

#1 Post by usul »

Hey guys,

I'm looking for a way to include buttons in the text box to fuction as a sort of hud. These buttons would allow the player to reach a screen and perform actions after which he could resume the game. Is this possible/simple?

If anyone can point me in the right direction for this I'd appreciate it.
Last edited by usul on Fri Apr 24, 2009 8:53 am, edited 1 time in total.
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
killdream
Veteran
Posts: 325
Joined: Wed Nov 05, 2008 1:05 pm
Projects: EVūL (WIP), insilo (WIP), Cute Demon Crashers!
Deviantart: robotlolita
Github: robotlolita
Location: World's End (aka Brazil)
Contact:

Re: Buttons on the text box/hud

#2 Post by killdream »

For text box, you mean, the dialog box? There's a recipe in Ren'Py's cookbook for it.

Here you go:
http://renpy.org/wiki/renpy/doc/cookboo ... _Game_Menu

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Buttons on the text box/hud

#3 Post by usul »

Cool, it works!

I only have one bug and that's if the button is pressed twice, you see the page, but then once you exit the page is brought up again.

Is there a way to make this button toggle the page instead of just calling it?

Code: Select all

ui.textbutton("Inventory", clicked=ccinc("inventory"), xminimum=80)
Oh and how do I replace the text buttons by custom images?
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Buttons on the text box/hud

#4 Post by JQuartz »

usul wrote:Is there a way to make this button toggle the page instead of just calling it?
You can use if like so:

Code: Select all

if show_button:
    ui.textbutton("Inventory", clicked=ccinc("inventory"), xminimum=80)
So by adding a show_button=None in the inventory, everytime the player calls the inventory, the button disappears. Then right before the return, put a show_button=True so that the inventory button would appear after the player returns from the inventory.
usul wrote:Oh and how do I replace the text buttons by custom images?
You can use ui.imagebutton. You can read about it here:http://www.renpy.org/wiki/renpy/doc/ref ... magebutton
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Buttons on the text box/hud

#5 Post by usul »

Code: Select all

On line 165 of /home/usul/system-addict_001/game/script.rpy: expected statement.
show_button=None
           ^

On line 173 of /home/usul/system-addict_001/game/script.rpy: expected statement.
show_button=True
           ^
How do I do this show button thing so I don't get an error?

Thanks in advance.
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Dusty
Regular
Posts: 126
Joined: Fri Jul 25, 2008 11:51 pm
Contact:

Re: Buttons on the text box/hud

#6 Post by Dusty »

You should probably be writing

Code: Select all

$ show_button = False
#...
$ show_button = True
with a $ sign. I personally don't think it's a good idea to use the value None, but you can use that instead of False if you want and it would work the same.

(by the way, I'm expanding the Button Game Menu page again as I type this because there have been a few questions about that lately)

EDIT: Okay, I added a humongous section near the end, and I still haven't even touched how the "clicked=x" portion works and what to do there. I'm a little scared that I might have gone too lengthy, but there's also the problem that I'm not explaining how the functions work well enough for non-programmers to understand. Comments would be nice.

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Buttons on the text box/hud

#7 Post by usul »

Ok while trying to add images to replace the text buttons I got an error:

Code: Select all

Exception: ui.interact called with non-empty widget/layer stack. Did you forget a ui.close() somewhere?
Here's the full code of that section:

Code: Select all

init python:

    # Give us some space on the right side of the screen.
    style.window.right_padding = 100

    def toggle_skipping():
        config.skipping = not config.skipping

    show_button_game_menu = True

    def button_game_menu():

        if show_button_game_menu:

            # to save typing
            ccinc = renpy.curried_call_in_new_context

            ui.vbox(xpos=0.99, ypos=0.98, xanchor='right', yanchor='bottom')
            #ui.textbutton("Inventory", clicked=ccinc("inventory"), xminimum=80)
            
            ui.frame(xalign=.5,yalign=.5)
            ui.imagebutton("images/system/inv_icon.png", "images/system/inv_icon_hover.png", clicked=ccinc("inventory"))
            ui.interact()
                       
            ui.textbutton("Save", clicked=ccinc("_game_menu_save"), xminimum=80)
            ui.textbutton("Load", clicked=ccinc("_game_menu_load"), xminimum=80)
            ui.textbutton("Prefs", clicked=ccinc("_game_menu_preferences"), xminimum=80)
            ui.close()


    config.overlay_functions.append(button_game_menu)
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Dusty
Regular
Posts: 126
Joined: Fri Jul 25, 2008 11:51 pm
Contact:

Re: Buttons on the text box/hud

#8 Post by Dusty »

You should probably take out the ui.interact.

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Buttons on the text box/hud

#9 Post by usul »

Ok very cool!

How do I get rid of the box around my image. It's a box created with the theme's color. In fact I'd like to get rid of the theme altogether in other areas like the main menu and such. I bet there's a command fo that too right?
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Dusty
Regular
Posts: 126
Joined: Fri Jul 25, 2008 11:51 pm
Contact:

Re: Buttons on the text box/hud

#10 Post by Dusty »

usul wrote:Ok very cool!

How do I get rid of the box around my image. It's a box created with the theme's color.
Remove the ui.frame().
usul wrote: In fact I'd like to get rid of the theme altogether in other areas like the main menu and such.
You mean create your own theme? ("Getting rid" of it might cause problems, such as not being able to see the main menu at all and thus the player not being able to play your game. :P) Creating your own theme is a little bit harder.

The documentation is over at renpy.org/wiki, on pages such as Customizing the Interface and Properties and Styles. If you want to make the menus into images, layout.imagemap_main_menu helps. (I don't really know what you're trying to do here, so yeah...)

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Buttons on the text box/hud

#11 Post by usul »

Ok removing the ui frame worked except it got rid of the coordonates for the placement of the button. It's now in the upper left corner by default.

I tried adding them to the image line but I get an error.
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Buttons on the text box/hud

#12 Post by usul »

Ok I figured it out. Adding the following at the end did it:

Code: Select all

xalign=.98,yalign=0.8
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Post Reply

Who is online

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