Conditional Menu

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.
Message
Author
LORD MJ
Newbie
Posts: 12
Joined: Fri Apr 08, 2011 3:10 pm
Contact:

Conditional Menu

#1 Post by LORD MJ » Wed Apr 13, 2011 4:24 am

I've ran in to a another dilemma. I hope that someone can help me.

So I want to create a custom menu that's always show on the screen and it enables the player to move from one room to another.

The menu is shown, but clicking on the buttons doesn't do anything. Now I know that something needs to be done in the menu code to make it work but I don't know how.

Also I want those functions of the menu buttons to change. For example, player can't enter a specific room until he/she has done specific action.

I hope that someone can post a simple code and explain how it works.

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Conditional Menu

#2 Post by Alera » Wed Apr 13, 2011 4:26 am

Could you post the codes you use now? It will make it easier to modify.
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

LORD MJ
Newbie
Posts: 12
Joined: Fri Apr 08, 2011 3:10 pm
Contact:

Re: Conditional Menu

#3 Post by LORD MJ » Wed Apr 13, 2011 2:47 pm

Sure, here is the code.

Code: Select all

init python:    
       
    meni_kuca = True
       
    def meni_kuca_funk():
        if meni_kuca:
            ui.hbox(xpos=0, ypos=0.75, xanchor='left', yanchor='bottom')
            ui.textbutton("Kuhinja", clicked=kuhinja, xminimum=80)
            ui.textbutton("Stepenice", clicked=stepenice, xminimum=80)
            ui.close()
    
    config.window_overlay_functions.append(meni_kuca_funk)
The code is in its own file to keep things organized.

shuen
Regular
Posts: 72
Joined: Tue Mar 22, 2011 2:36 pm
Contact:

Re: Conditional Menu

#4 Post by shuen » Wed Apr 13, 2011 7:05 pm

It seems you need to def what you are going to do when the kuhinja and stepenice button being clicked

Code: Select all

    def kuhinja():
        #do something

    def stepenice():
        #do something
Image
.Traditional Chinese Site.
~Illustrator+Graphic/Web Designer~

LORD MJ
Newbie
Posts: 12
Joined: Fri Apr 08, 2011 3:10 pm
Contact:

Re: Conditional Menu

#5 Post by LORD MJ » Thu Apr 14, 2011 2:31 am

But what does go under def?

I already tried with jump kuhinja, to jump to the label in my code but it says it's an invalid syntax.

shuen
Regular
Posts: 72
Joined: Tue Mar 22, 2011 2:36 pm
Contact:

Re: Conditional Menu

#6 Post by shuen » Thu Apr 14, 2011 8:15 am

did you tried this?
clicked=ui.jumps("kuhinja")
http://www.renpy.org/wiki/renpy/doc/ref ... s/ui.jumps

or ui.return may help...
http://www.renpy.org/wiki/renpy/doc/ref ... ui.returns
see the second example in this reference
Image
.Traditional Chinese Site.
~Illustrator+Graphic/Web Designer~

User avatar
Airetta
Regular
Posts: 25
Joined: Sat Apr 09, 2011 12:00 pm
Projects: Miracle Days: YourLife VS The Reality
Contact:

Re: Conditional Menu

#7 Post by Airetta » Thu Apr 14, 2011 9:10 am

humm hey i have a question in same condition

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.35, ypos=0.75, xanchor='bottom', yanchor='right')
            ui.textbutton("Skip", clicked=toggle_skipping, xminimum=80)
            ui.textbutton("Save", clicked=ccinc("_game_menu_save"), xminimum=80)
            ui.textbutton("Load", clicked=ccinc("_game_menu_load"), xminimum=80)
            ui.textbutton("Opt", clicked=ccinc("_game_menu_preferences"), xminimum=80)
            ui.textbutton("Menu", clicked=ccinc(), xminimum=80)
            ui.close()
this code shows vertical menu. i want to make it to horizontal menu. how?
Sorry guys, my English is so bad :D

My Blogsite: http://utysama.aoindonesia.net/
Miracle Days: YourLife VS TheReality: http://lemmasoft.renai.us/forums/viewto ... 5&p=129221

LORD MJ
Newbie
Posts: 12
Joined: Fri Apr 08, 2011 3:10 pm
Contact:

Re: Conditional Menu

#8 Post by LORD MJ » Thu Apr 14, 2011 9:36 am

@Airetta: Use hbox instead of vbox.

@shuen: I think that ui,jumps is the functions I need. I'll have a look at it later when I have time.

LORD MJ
Newbie
Posts: 12
Joined: Fri Apr 08, 2011 3:10 pm
Contact:

Re: Conditional Menu

#9 Post by LORD MJ » Thu Apr 14, 2011 5:04 pm

The menu is now functional and I've gotten it work with conditions.

Now one last things bugs me. For example, player was told that he can't enter a room. And using a menu he needs to go back to previous rooms to complete some tasks. I have a problem if I click after the game told me that I can't do anything it'll finish the game or go to the next instructions.

I want Ren'Py to wait until the player has clicked an option in the menus.

shuen
Regular
Posts: 72
Joined: Tue Mar 22, 2011 2:36 pm
Contact:

Re: Conditional Menu

#10 Post by shuen » Thu Apr 14, 2011 7:29 pm

You need to loop the game until the tasks complete
for example:

Code: Select all

# The game starts here.
label start:
    # All opening staffs put here
    "I enter the Hotel"
    $ haskey = False
    jump lobby

# The game loop here    
label lobby:
     "I'm in lobby now"
     jump chooser 

label chooser:
    "Choose a room"
    menu:
        "Room1":
            jump room1
        "Room2":
            jump room2
        "Room3":
            jump room3
            
label room1:
    if haskey:
        "I unlock the door of Room1!"
        return # end the game loop
    else:
        "The door is locked, I need a key to open it..."
        jump lobby

label room2:
    "This room is empty..."
    jump lobby
    
label room3:
    "Hey I find a key!"
    $ haskey = True
    jump lobby
    

Image
.Traditional Chinese Site.
~Illustrator+Graphic/Web Designer~

User avatar
Mild Curry
Regular
Posts: 107
Joined: Fri Jul 02, 2010 3:03 pm
Projects: That's The Way The Cookie Crumbles
Organization: TwinTurtle Games
Contact:

Re: Conditional Menu

#11 Post by Mild Curry » Fri Apr 15, 2011 2:11 am

Hmm...well, looping might work, but there's a simpler solution.
Try adding:

Code: Select all

 func = ui.interact()
 func() 
right after your ui.close().

It pauses the program until the user clicks a button. That is what you wanted,right?

LORD MJ
Newbie
Posts: 12
Joined: Fri Apr 08, 2011 3:10 pm
Contact:

Re: Conditional Menu

#12 Post by LORD MJ » Fri Apr 15, 2011 5:50 am

Thank you both. I think that Curry's solution is better so I'll use his.

But now I get an error.

Code: Select all

Exception: ui.interact called with non-empty widget/layer stack. Did you forget a ui.close() somewhere?
And the code looks like this.

Code: Select all

init python:    
       
    meni_kuca = True
     
    def meni_kuca_funk():
        if meni_kuca:
            ui.hbox(xpos=0, ypos=0.75, xanchor='left', yanchor='bottom')
            ui.textbutton("Kuhinja", clicked=ui.jumps("kuhinja"), xminimum=80)
            ui.close()
            func = ui.interact()
            func()
            
            
    config.window_overlay_functions.append(meni_kuca_funk)
First I thought that func needs to be replaced with my functions name, meni_kuca_funk. But that doesn't help. What is wrong here?

User avatar
Mild Curry
Regular
Posts: 107
Joined: Fri Jul 02, 2010 3:03 pm
Projects: That's The Way The Cookie Crumbles
Organization: TwinTurtle Games
Contact:

Re: Conditional Menu

#13 Post by Mild Curry » Sat Apr 16, 2011 4:14 am

Ahh....okay. It seems that that solution won't work inside a function. The code runs fine when placed in the regular program, but something goes screwy when it's inside a function.


I'm sorry; I haven't had much experience in that area, so I have no idea why it works that way...^^'';

LORD MJ
Newbie
Posts: 12
Joined: Fri Apr 08, 2011 3:10 pm
Contact:

Re: Conditional Menu

#14 Post by LORD MJ » Sat Apr 16, 2011 5:23 am

I've put it in my main script. Here is that part.

Code: Select all

label kuhinja:
    "Test"
    if kuhinja:
        c "Rucak!"
        $ ui.interact()
    else:
        c "Moram prvo da operem ruke."
        $ kuhinja = True
        c "Ruke su oprane."
        $ ui.interact()
Now it doesn't exit from my game but it hides text box and the menu from the screen for some reason.

User avatar
Ellume
Regular
Posts: 36
Joined: Tue Apr 06, 2010 2:57 am
Contact:

Re: Conditional Menu

#15 Post by Ellume » Sat Apr 16, 2011 7:22 am

shuen's method of looping works. Based off the code you've shown you could try something like this:

Code: Select all

init python:    
    meni_kuca = False
    def meni_kuca_funk():
        if meni_kuca:
            ui.hbox(xpos=0, ypos=0.75, xanchor='left', yanchor='bottom')
            ui.textbutton("Kuhinja", clicked=ui.jumps("kuhinja"), xminimum=80)
            ui.close()            
    config.window_overlay_functions.append(meni_kuca_funk)

label story_before:
    "Stuff happens earlier in story"
    $ meni_kuca = True
    jump waitforclick

label waitforclick:
    "Waiting for the button to be clicked"
    if meni_kuca:
        jump waitforclick
        
label kuhinja:
    $ meni_kuca = False
    "Turn off button and the story continues on"
    #etc etc whatever

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]