Game Menu Buttons

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
PyTom
Ren'Py Creator
Posts: 15893
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:

Game Menu Buttons

#1 Post by PyTom » Thu Mar 10, 2005 11:42 pm

Here's some code I whipped together that adds buttons on the screen that link to various parts of the game menu, and also a button that toggles skipping.

Code: Select all

# This file adds a number of buttons to the lower-right hand corner of
# the screen. Three of these buttons jump to the game menu, which
# giving quick access to Load, Save, and Prefs. The fourth button
# toggles skipping, to make that more convenient.

init:

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

    python:

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

        def button_game_menu():

            # to save typing
            ccinc = renpy.curried_call_in_new_context

            ui.vbox(xpos=0.98, ypos=0.98, xanchor='right', yanchor='bottom')
            ui.textbutton("Skip", clicked=toggle_skipping)
            ui.textbutton("Save", clicked=ccinc("_game_menu_save"))
            ui.textbutton("Load", clicked=ccinc("_game_menu_load"))
            ui.textbutton("Prefs", clicked=ccinc("_game_menu_preferences"))
            ui.close()


        config.overlay_functions.append(button_game_menu)
Drop it into your game directory to try it out. If you like image buttons, you could get them by changing the calls to textbutton into calls to imagebutton, with the appropriate image files as arguments. (Ask me if this is unclear.)

User avatar
Strum
Veteran
Posts: 215
Joined: Mon Sep 28, 2009 10:38 am
Contact:

Re: Game Menu Buttons

#2 Post by Strum » Mon Sep 28, 2009 10:42 am

Hi, this piece of code is just what I needed for my VN project. However, can you please rewrite the code to use imagebuttons instead of textbuttons? Thanks
Image

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

Re: Game Menu Buttons

#3 Post by Aleema » Mon Sep 28, 2009 1:14 pm

Strum wrote:Hi, this piece of code is just what I needed for my VN project. However, can you please rewrite the code to use imagebuttons instead of textbuttons? Thanks
Surely you could do that ... I mean, you would have to supply the images to begin with. o_O

User avatar
Strum
Veteran
Posts: 215
Joined: Mon Sep 28, 2009 10:38 am
Contact:

Re: Game Menu Buttons

#4 Post by Strum » Mon Sep 28, 2009 2:11 pm

I don't quite understand how the imagebuttons work. directly swapping the textbutton with imagebutton along with all the correct varibles in the brackets don't seem to work. I copy and pasted the code onto my own script then tried to change the textbuttons for imagebuttons. Ah, I should mention that I just started to use ren'py yesterday. Anyway, swapping

ui.textbutton("Skip", clicked=("Skip", clicked=toggle_skipping)

for

ui.imagebutton("SkipA.png", "SkipB.png", clicked=("Skip", clicked=toggle_skipping)

gives me an error of

Exception: Syntax error on line 64 of C:\Test/game/script.rpy

While compiling python block starting at line 56 of C:\Test/game/script.rpy.

-- Full Traceback ------------------------------------------------------------

File "C:\renpy-6.9.3\renpy\bootstrap.py", line 260, in bootstrap
File "C:\renpy-6.9.3\renpy\main.py", line 171, in main
File "C:\renpy-6.9.3\renpy\script.py", line 477, in load_script
File "C:\renpy-6.9.3\renpy\script.py", line 155, in __init__
File "C:\renpy-6.9.3\renpy\script.py", line 371, in load_appropriate_file
File "C:\renpy-6.9.3\renpy\script.py", line 333, in load_file
File "C:\renpy-6.9.3\renpy\script.py", line 426, in update_bytecode
File "C:\renpy-6.9.3\renpy\python.py", line 250, in py_compile_exec_bytecode
File "C:\renpy-6.9.3\renpy\python.py", line 234, in py_compile
Exception: Syntax error on line 64 of C:\Test/game/script.rpy

While compiling python block starting at line 56 of C:\Test/game/script.rpy.
Image

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Game Menu Buttons

#5 Post by Showsni » Mon Sep 28, 2009 3:57 pm

You seem to have repeated part of the code; instead of
ui.textbutton("Skip", clicked=toggle_skipping)
you've got
ui.textbutton("Skip", clicked=("Skip", clicked=toggle_skipping)
.
Try
ui.imagebutton("SkipA.png", "SkipB.png", clicked=toggle_skipping)
, maybe?

User avatar
Strum
Veteran
Posts: 215
Joined: Mon Sep 28, 2009 10:38 am
Contact:

Re: Game Menu Buttons

#6 Post by Strum » Mon Sep 28, 2009 4:07 pm

Thanks, that seemed to do the trick. I can't believe I added one too many brackets.
Image

User avatar
Thee Forsaken One
Regular
Posts: 196
Joined: Sun Mar 01, 2009 8:10 pm
Completed: RE: Alistair++; Backstage Pass; Three Guys That Paint; The Reject Demon Toko - Ch 0; The Menagerie
Projects: Winning Hearts; Astral Hours
Organization: Forsaken Productions
Tumblr: ForsakenProductions
Deviantart: TheeForsakenOne
Location: Scotland
Contact:

Re: Game Menu Buttons

#7 Post by Thee Forsaken One » Wed Jan 27, 2010 11:08 am

I've been trying to set up one for my own game but it won't show up in-game. :? Any ideas what the problem is?

I originally had the imagebuttons outside of vboxes but that didn't seem to work so I tried it within and that didn't work either. :/

Code: Select all

init python:
    
    def toggle_skipping():
        config.skipping = not config.skipping
        
    def toggle_cps():
        config.has_cps = not config.has_cps
             
    def button_game_menu():

        # to save typing
        ccinc = renpy.curried_call_in_new_context
        
        ui.vbox( xpos=622, ypos=398)
        ui.imagebutton("GUI/RLoption.png", "GUI/RLoption1.png", clicked=ccinc("_game_menu_preferences"), hover_sound="sounds/hover.wav", activate_sound="sounds/click.wav")
        ui.close()
        ui.vbox( xpos=662, ypos=550)
        ui.imagebutton("GUI/RLskip.png", "GUI/RLskip1.png", clicked=toggle_skipping,  hover_sound="sounds/hover.wav", activate_sound="sounds/click.wav")
        ui.close()
        ui.vbox( xpos=704, ypos=527)
        ui.imagebutton("GUI/RLauto.png", "GUI/RLauto.png", clicked=toggle_cps,  hover_sound="sounds/hover.wav", activate_sound="sounds/click.wav")
        ui.close()
        
        config.overlay_functions.append(button_game_menu)

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

Re: Game Menu Buttons

#8 Post by Alex » Wed Jan 27, 2010 12:47 pm

I think, the problem is indentation in last line. Try

Code: Select all

    def button_game_menu():

        # to save typing
        ccinc = renpy.curried_call_in_new_context
        
        ui.vbox( xpos=622, ypos=398)
        ui.imagebutton("GUI/RLoption.png", "GUI/RLoption1.png", clicked=ccinc("_game_menu_preferences"), hover_sound="sounds/hover.wav", activate_sound="sounds/click.wav")
        ui.close()
        ui.vbox( xpos=662, ypos=550)
        ui.imagebutton("GUI/RLskip.png", "GUI/RLskip1.png", clicked=toggle_skipping,  hover_sound="sounds/hover.wav", activate_sound="sounds/click.wav")
        ui.close()
        ui.vbox( xpos=704, ypos=527)
        ui.imagebutton("GUI/RLauto.png", "GUI/RLauto.png", clicked=toggle_cps,  hover_sound="sounds/hover.wav", activate_sound="sounds/click.wav")
        ui.close()
        
    config.overlay_functions.append(button_game_menu)

User avatar
Thee Forsaken One
Regular
Posts: 196
Joined: Sun Mar 01, 2009 8:10 pm
Completed: RE: Alistair++; Backstage Pass; Three Guys That Paint; The Reject Demon Toko - Ch 0; The Menagerie
Projects: Winning Hearts; Astral Hours
Organization: Forsaken Productions
Tumblr: ForsakenProductions
Deviantart: TheeForsakenOne
Location: Scotland
Contact:

Re: Game Menu Buttons

#9 Post by Thee Forsaken One » Wed Jan 27, 2010 12:49 pm

Thanks that fixed it. I hate it when it's such a simple mistake. > <

Post Reply

Who is online

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