Button on screen that opens choice 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.
Post Reply
Message
Author
User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Button on screen that opens choice menu

#1 Post by TellerFarsight » Thu Jul 06, 2017 6:57 pm

I have a screen that displays an email, and I want to have a "Reply" button which brings up a choice menu over the top of the screen. Any idea how to do that?

Code: Select all

menu:
        nar "Someone asking you a question"
        "Yessir":
            "That doesn't really answer my question"
        "Nah":
            "I'll go ask someone else"

Code: Select all

screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action
So I can see how the choice screen is done here and I know how to use it with menu, but how do I call the choice screen with a button?

Code: Select all

textbutton "Reply" action Show("choice", [choice_items1])
$ choice_items1 = ["Yessir":"That doesn't really answer my question", "Nah":"I'll go ask someone else"] #???
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Button on screen that opens choice menu

#2 Post by TellerFarsight » Sun Jul 09, 2017 7:58 am

Code: Select all

screen email_display(folder, sender, subject, email, replyable, choice_items):
    add "gui/nvl.png"
    style_prefix "email_display"
    use email_display2(sender, subject)
    use email_display3(folder)
    textbutton "Return" action Hide('email_display') at returnbuttonmail
    if replyable:
        textbutton "Reply" action Show("choice", "choice_items")
    frame:
        area (10, 180, 780, 360)
        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True
            vbox:
                text "[email]"

show screen email_display("Inbox", "Someone", "Something", "Bla Bla Bla", True, ["Yessir":"That doesn't really answer my question", "Nah":"I'll go ask someone else"]) ### I'm getting a syntax error on this line
I tried working it into the show screen, but I'm getting a syntax error here.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
vollschauer
Veteran
Posts: 228
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

Re: Button on screen that opens choice menu

#3 Post by vollschauer » Mon Jul 10, 2017 3:13 am

Then post the error ...

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Button on screen that opens choice menu

#4 Post by TellerFarsight » Mon Jul 10, 2017 6:59 am

I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/day0scenes.rpy", line 173, in script
call screen email_display("Laplace Mail", "The Observer", "Laplace Mail", "Good morning.\nHere is today's NEWS.\n\n1. At around 16:00, a man will {color=#ffca1e}be killed{/color} in Shibuya-ku Aoyama apartment. The wounds on the corpse are consistent with an attack by a large carnivorous beast.\n\n2. A large {color=#ffca1e}explosion{/color} will occur in Minato-ku Aoyama at 19:00. The cause is unknown.\n\n3. At 21:00, a {color=#ffca1e}blackout{/color} will affect the entire Tokyo metropolitan area.\n\nHave a nice day.", True, ["Yessir":"That doesn't really answer my question", "Nah":"I'll go ask someone else"])
File "renpy/common/000statements.rpy", line 466, in execute_call_screen
args, kwargs = a.evaluate()
SyntaxError: invalid syntax (game/day0scenes.rpy, line 173)

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

Full traceback:
File "game/day0scenes.rpy", line 173, in script
call screen email_display("Laplace Mail", "The Observer", "Laplace Mail", "Good morning.\nHere is today's NEWS.\n\n1. At around 16:00, a man will {color=#ffca1e}be killed{/color} in Shibuya-ku Aoyama apartment. The wounds on the corpse are consistent with an attack by a large carnivorous beast.\n\n2. A large {color=#ffca1e}explosion{/color} will occur in Minato-ku Aoyama at 19:00. The cause is unknown.\n\n3. At 21:00, a {color=#ffca1e}blackout{/color} will affect the entire Tokyo metropolitan area.\n\nHave a nice day.", True, ["Yessir":"That doesn't really answer my question", "Nah":"I'll go ask someone else"])
File "C:\Users\-\Desktop\renpy-6.99.12.4-sdk\renpy\ast.py", line 1706, in execute
self.call("execute")
File "C:\Users\-\Desktop\renpy-6.99.12.4-sdk\renpy\ast.py", line 1724, in call
return renpy.statements.call(method, parsed, *args, **kwargs)
File "C:\Users\-\Desktop\renpy-6.99.12.4-sdk\renpy\statements.py", line 145, in call
return method(parsed, *args, **kwargs)
File "renpy/common/000statements.rpy", line 466, in execute_call_screen
args, kwargs = a.evaluate()
File "C:\Users\-\Desktop\renpy-6.99.12.4-sdk\renpy\ast.py", line 184, in evaluate
args.append(renpy.python.py_eval(v, locals=scope))
File "C:\Users\-\Desktop\renpy-6.99.12.4-sdk\renpy\python.py", line 1748, in py_eval
code = py_compile(code, 'eval')
File "C:\Users\-\Desktop\renpy-6.99.12.4-sdk\renpy\python.py", line 584, in py_compile
raise e
SyntaxError: invalid syntax (game/day0scenes.rpy, line 173)
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
vollschauer
Veteran
Posts: 228
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

Re: Button on screen that opens choice menu

#5 Post by vollschauer » Mon Jul 10, 2017 9:04 am

I think you can't pass this "dict" : ["Yessir":"That doesn't really answer my question", "Nah":"I'll go ask someone else"]

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

Re: Button on screen that opens choice menu

#6 Post by Alex » Mon Jul 10, 2017 2:10 pm

Why do you want to use choice screen in the first place? You can create your own screen that would have similar appearence but will do exactly the things you need it to do... And you could pass to it the values you like...
Also it's not a good idea to make your screens show lots of stuff 'cause you might face the issues with saving the game state. It might be better to show all the complex stuff in labels...
https://www.renpy.org/doc/html/save_load_rollback.html


As for ["Yessir":"That doesn't really answer my question", "Nah":"I'll go ask someone else"] part - it either should be a dict (figure bracets {}) or a list (then elements must be separated with commas)

Code: Select all

{"Yessir":"That doesn't really answer my question", "Nah":"I'll go ask someone else"}
['"Yessir":"That doesn\'t really answer my question"', '"Nah":"I\'ll go ask someone else"']


Anyway, check this links:
https://www.renpy.org/doc/html/statemen ... splay_menu
https://www.renpy.org/wiki/renpy/doc/re ... splay_menu

User avatar
Milkymalk
Miko-Class Veteran
Posts: 747
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Button on screen that opens choice menu

#7 Post by Milkymalk » Mon Jul 10, 2017 2:36 pm

I second what Alex said; it's better to make your custom screen than try to abuse the choice screen.

Also, I think you are not understanding the choice screen as well as you believe (I don't understand it 100% myself). items there is a list of objects with the fields .caption and .action, not a dictionary.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Button on screen that opens choice menu

#8 Post by TellerFarsight » Mon Jul 10, 2017 11:22 pm

First off, yes Alex I forgot to put the right brackets for the dictionary. Once I fixed that, it returned with another error affirming what you said, MilkyMalk. I can't just pass a dictionary to the choice screen, it has to be a list of tuples. The renpy.display_menu works, because it uses the look of the choice screen (I wanted it to look identical to the choice screen, which is why I wanted to try and call the choice screen with arguments of some kind). When I tried Function(renpy.display_menu, "stuff") it gave me a "you can't start an interaction within an interaction" error so I made it call a label and that worked.
I want to make only a few certain emails "replyable" which is hard to do with the dictionary data system I have right now. Probably tomorrow morning I'll try and redefine everything using a class and that should fix it.
Thanks for the help!
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Button on screen that opens choice menu

#9 Post by TellerFarsight » Tue Jul 11, 2017 8:35 am

Code: Select all

init -1 python:
    class Email(object):
        def __init__(self, sender, subject, body):
            self.sender = sender
            self.subject = subject
            self.body = body
    class ReplyableEmail(Email):
        def __init__(self):
            self.replyable = True
            
default email4 = Email("sender4", "subject4", "body4")
default email5 = ReplyableEmail("sender5", "subject5", "body5")
                        
default replyable = False

screen email_display(folder, email):
    modal True
    add "gui/nvl.png"
    style_prefix "email_display"
    use email_display2(email)
    use email_display3(folder)
    if not at_checkpoint:
        textbutton "Return" action Return() at returnbuttonmail
    else:
        textbutton "Return" action Hide("email_display") at returnbuttonmail
    if email.replyable:
        textbutton "Reply" action Function(renpy.call, "mailreply")
### And there's more code to this screen but I think it's irrelevant here.
So I reworked everything into a class (Really new to it so I really don't understand it yet) like this, and I've gotten everything to work the way it did with dictionaries, but I'm not sure how to use a derived class to create the "replyable" condition. I get this error:

TypeError: __init__() takes exactly 1 argument (4 given)

Am I just... Is this not how you use derived classes? Am I just doing it wrong or should I not be using a derived class at all? What are they used for, generally?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
Milkymalk
Miko-Class Veteran
Posts: 747
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Button on screen that opens choice menu

#10 Post by Milkymalk » Tue Jul 11, 2017 9:41 am

Nope, you have to do it like this:

Code: Select all

class Pet(object):
    def __init__(self, name, species):
        self.name = name
        self.species = species

class Dog(Pet):
    def __init__(self, name, chases_cars):
        Pet.__init__(self, name, 'dog')
        self.chases_cars = chases_cars
In short, you have to call the specific __init__ method of the parent class with the arguments and for that you need the child class to accept them in the first place.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: Button on screen that opens choice menu

#11 Post by DannyGMaster » Tue Jul 11, 2017 10:28 am

Milkymalk wrote:Nope, you have to do it like this:

Code: Select all

class Pet(object):
    def __init__(self, name, species):
        self.name = name
        self.species = species

class Dog(Pet):
    def __init__(self, name, chases_cars):
        Pet.__init__(self, name, 'dog')
        self.chases_cars = chases_cars
In short, you have to call the specific __init__ method of the parent class with the arguments and for that you need the child class to accept them in the first place.
I had a very similar problem, so that's how it's done, I somehow knew I had to call the parent's init method first, otherwise we would be just overwriting the method(I think), but I was trying to call it with super() to no avail, this does seem more correct, thanks, Milkymalk.
The silent voice within one's heart whispers the most profound wisdom.

Post Reply

Who is online

Users browsing this forum: EnajoriYui, Sterkiherz