How do I put items in a custom choice screen?[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.
Message
Author
User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

How do I put items in a custom choice screen?[SOLVED]

#1 Post by TellerFarsight »

Code: Select all

screen location_list(items):
    style_prefix "location_list"
    frame:
        area (10, 60, 200, 480)
        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True
            vbox:
                label "PLACE:"
                for i in items:
                    textbutton i.caption action i.action
I'm trying to make a custom choice screen, but I don't know how to supply the items to it. For a regular choice menu, you just call it with

Code: Select all

menu:
    "Whatever":
        jump whatever
    "Whateverpart2":
        jump whateverer
but how do I use my custom one?

Note: I don't want to just replace the original choice screen, I want to preserve that as well as having this other screen.
Last edited by TellerFarsight on Thu Jun 22, 2017 5:15 pm, edited 1 time in total.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: How do I put items in a custom choice screen?

#2 Post by DannyGMaster »

I'm trying to do something simmilar for my game.

As for suplying the items it could be as simple as doing it when you show the screen:

Code: Select all

default my_locations = ['Park', 'Library', 'School', 'Home']

label start:
    show screen location_list(my_locations)

But you also must create a function to determine what caption and action are for each item.

In my case, I just needed to jump to a specific label, so the screen would look like this:

Code: Select all

screen location_list(items):
    style_prefix "location_list"
    frame:
        area (10, 60, 200, 480)
        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True
            vbox:
                text "PLACES:"
                for i in items:
                    textbutton i action Jump(i)

default my_locations = ['park', 'school']

label start:

    "Where should we go?"

    show screen location_list(my_locations)

    label park:
        "Let's go to the park"

    label school:
        "Let's go to school"
But you probably want to find the entire choice function, make a copy of it and adapt it to your own needs.
The silent voice within one's heart whispers the most profound wisdom.

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

Re: How do I put items in a custom choice screen?

#3 Post by TellerFarsight »

First of all, works like a charm! Yeah!

Follow up question:

So, in this case the caption shown on screen is the same as the label that it jumps to, but can I make the label name something else?

Code: Select all

    call screen location_list(["Ikebukuro", "Ueno"])
    label Ikebukuro:
        call screen sub_location_list(["West", "East"])
    label Ueno:
        call screen sub_location_list(["West", "East"])
# West and East Ikebukuro
    label West:
        "The sun gets in your face"
    label East:
        "other stuff"
# West and East Ueno
    label West:
        "The sunset or something?"
    label East:
        "stuff"
The problem here is that I want the sublocations to lead to different things, but using

Code: Select all

textbutton i action Jump(i)
forces the caption and the label to both be the name of the item. Is there a way to call them something else?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: How do I put items in a custom choice screen?

#4 Post by Alex »

Well, if you want to use two (or more) different looking in-game menus, you can modify the choice screen in screens.rpy file. Like adding checks for some variable values.

Code: Select all

screen choice(items):
    
    if my_var == 0:
        window:
            background None
            align (0.5, 0.0)
            vbox:
                align (0.5, 0.5)
                for caption, action, chosen in items:

                    if action:

                        button:
                            action action
                            style "menu_choice_button"

                            text caption style "menu_choice"

                    else:
                        text caption style "menu_caption"

    elif my_var == 1:
        window:
            style "menu_window"
            xalign 0.5
            yalign 0.5

            vbox:
                style "menu"
                spacing 2

                for caption, action, chosen in items:

                    if action:

                        button:
                            action action
                            style "menu_choice_button"

                            text caption style "menu_choice"

                    else:
                        text caption style "menu_caption"

Code: Select all

default my_var = 0

# The game starts here.
label start:
    "..."
    menu:
        "Choice 1":
            pass
        "Choice 2":
            pass
    $ my_var = 1
    "... ..."
    menu:
        "Choice 3":
            pass
        "Choice 4":
            pass
    "?"

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

Re: How do I put items in a custom choice screen?

#5 Post by TellerFarsight »

What I'm ultimately trying to create is this screen.
The menu on the left is location_list and the menu on the right is sub_location_list
The sub_location_list is a list of actions that return different dialogue depending on the location, so I want to label them differently.

I can see what you mean, Alex, but I'm not trying to do variants in that sense. I want to have these two screens up at the same time.
Attachments
.
.
.
.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: How do I put items in a custom choice screen?

#6 Post by DannyGMaster »

I see, I have played Devil Survivor so I understand what you want. The sub location list can be another screen, with
a different set of actions for each button. For each button action in location_list, you could use renpy.show_screen to have that corresponding screen appear on the right. You would need to make a sub_location list for every possible area of town. Otherwise find how choice.caption and choice.action work and adapt, I would love to do that but I still don't know where in Ren'Py is choice located. I'm not talking about the choice screen, but the function that handles choices and contains the caption and action methods. If all else fails I will try and script it myself, for Shin Megami Tensei.
The silent voice within one's heart whispers the most profound wisdom.

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

Re: How do I put items in a custom choice screen?

#7 Post by Alex »

Ah, in this case you need to store your data (places, actions for them and corresponding labels names and etc.) in some variable, like DannyGMaster said, then you can create your own screen to show this data whatever way you like. Kind of example

Code: Select all

screen my_scr(places):
    frame:
        pos (0.1, 0.2)
        xysize(200,400)
        vbox:
            text "Places:"
            null height 5
            for place in places:
                button:
                    text place["place"]
                    action [Show("img_scr", i=place["img"]), Show("my_2_scr",l=place["actions_list"])]
                null height 5

screen img_scr(i):
    add i pos(0.4,0.2)

screen my_2_scr(l):
    frame:
        pos (0.4, 0.5)
        xysize(400,220)
        vbox:
            text "Actions:"
            null height 5
            if not renpy.get_screen("say"):
                for act in l:
                    button:
                        text act["act_name"]
                        action Return(act["res"])
                    null height 5
image pl_1:
    size(150,150)
    Solid("#c00")
    
image pl_2:
    size(150,150)
    Solid("#00c")
    
# The game starts here.
label start:
    $ my_data = [ {"place":"Place 1", "img":"pl_1", "actions_list":[{"act_name":"Look around", "res":"It's Place 1 here."}, {"act_name":"Listen", "res":"It's quiet here."},]},
        {"place":"Place 2", "img":"pl_2", "actions_list":[{"act_name":"Look around", "res":"It's Place 2 here."}, {"act_name":"Listen", "res":"Hey, there's some music playing..."},]},
        ]
    "..."
    show screen my_scr(my_data)
    
label loop:
    $ txt = ui.interact()
    "[txt]"
    jump loop

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

Re: How do I put items in a custom choice screen?

#8 Post by TellerFarsight »

Yikes!

Maybe I can work my way through that solution when I have less of a headache, but I tried just putting your code in as is, Alex. However, the Actions list doesn't appear.

It says Cannot Display (the whole slew of data) as text
Attachments
.
.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: How do I put items in a custom choice screen?

#9 Post by Alex »

That's ok - in my example actions won't show up if say box is onscreen (if not renpy.get_screen("say")). It looks like you've made textbox always stay on the screen... So, for test purposes comment this line and fix the indentation of the rest of the code or put window hide before label loop.

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

Re: How do I put items in a custom choice screen?

#10 Post by TellerFarsight »

Oh, you're right. I forgot about that bit.
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: How do I put items in a custom choice screen?

#11 Post by TellerFarsight »

Sorry about this, but I've got a couple more questions that I just can't find answers for.

1. Is there a way to hide all the screens using a button? When I hit one of the buttons like "Listen" the textbox just appears overtop the menus. Can they be hidden when the button is clicked, and then shown again once the little bit of dialogue is over?

2. Can the buttons in these menus be made into textbuttons or imagebuttons, so that I can make hover and idle states? Specifically, I want to make the coloured background states like in the default choice menu.

3. Can the "res" action at the end of this decision tree respond by jumping instead of just returning a single dialogue? I want it to go through more than one textbox before looping back, but it looks like I can only "res" with one.

Here's the portion of the script, where I made an *attempt* to solve 1. and 3. by jumping. However, this just returned with an error, because jump isn't something that can be done as a response.

Code: Select all

    $ at_checkpoint = True
    $ day0map1 = [
        {"place":"Place 1", "photo":"pl_1", "actions_list":
            [
                {"act_name":"Look around", "res":"It's Place 1 here."}, 
                {"act_name":"Listen", "res":"It's quiet here."},
                ]
            },
        {"place":"Place 2", "photo":"pl_2", "actions_list":
            [
                {"act_name":"Look around", "res": jump gobbledegook }, 
                {"act_name":"Listen", "res":"Hey, there's some music playing..."},
                ]
            },
        ]
    window hide
    show screen location_list(day0map1)
label loop:
    $ txt = ui.interact()
    "[txt]"
    jump loop
    
label gobbledegook:
    hide screen location_list
    hide screen sub_location_list
    hide screen location_photo
    "You look around and see Place 2 everywhere."
    "It's unsettling how completely it surround you."
    "and yet..."
    "it's comforting."
    show screen location_list
    show screen sub_location_list
    show screen location_photo
    jump loop
    
    return
Also, here's the bit of code at the end that codes for the button in question.

Code: Select all

            vbox:
                label "ACTION:"
                if not renpy.get_screen("say"):
                    for a in actions:
                        button:
                            text a["act_name"]
                            action Return(a["res"])
Can I change the action to allow for jumping as a response (not just jumping as an action, because that was one of the original problems that was avoided) and can I make this into an imagebutton or textbutton?
Attachments
An imagebutton like the one I want to make
An imagebutton like the one I want to make
Menu with textbox up in ya face
Menu with textbox up in ya face
Menu working fine
Menu working fine
Last edited by TellerFarsight on Thu Jun 22, 2017 8:47 am, edited 1 time in total.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: How do I put items in a custom choice screen?

#12 Post by DannyGMaster »

TellerFarsight wrote:
1. Is there a way to hide all the screens using a button? When I hit one of the buttons like "Listen" the textbox just appears overtop the menus. Can they be hidden when the button is clicked, and then shown again once the little bit of dialogue is over?
Yes, you can have the screen hide by checking if dialogue is being shown, by using a function called renpy.get_screen(). At the start of the screen before the frame and everything, put up an if that evaluates renpy.get_screen("say") (the dialogue screen), so if dialogue appears, the screen will hide and then
reappear when dialogue is over.
TellerFarsight wrote: 2. Can the buttons in these menus be made into textbuttons or imagebuttons, so that I can make hover and idle states? Specifically, I want to make the coloured background states like in the default choice menu.
Well, I'm pretty sure I've seen textbuttons with background image and changin states. However I don't know exactly where right now, it was with the old gui but surely the new has this feature as well.
TellerFarsight wrote: 3. Can the "res" action at the end of this decision tree respond by jumping instead of just returning a single dialogue? I want it to go through more than one textbox before looping back, but it looks like I can only "res" with one.
Well, "res" could be a list with more than one quote.

Code: Select all

'res':['Hey man.', 'How you doing?']
But I should be better having it jump and then return.
The silent voice within one's heart whispers the most profound wisdom.

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

Re: How do I put items in a custom choice screen?

#13 Post by TellerFarsight »

renpy.get_screen worked perfectly!

Here's what happened when I tried to do multiple dialogues.

I'm sorry if I made that unclear, but when I tried to use "res": jump gobbledegook it returned with a syntax error.
Some of the responses need to have multiple dialogues, some need character sprites with them, and of course I need one of these options to continue on with the story so we're not stuck in this loop forever. What I want is to respond with jump, but I can't figure out the language for it.
Attachments
Trying to have multiple dialogue bits
Trying to have multiple dialogue bits
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: How do I put items in a custom choice screen?

#14 Post by DannyGMaster »

TellerFarsight wrote:renpy.get_screen worked perfectly!

Here's what happened when I tried to do multiple dialogues.

I'm sorry if I made that unclear, but when I tried to use "res": jump gobbledegook it returned with a syntax error.
Some of the responses need to have multiple dialogues, some need character sprites with them, and of course I need one of these options to continue on with the story so we're not stuck in this loop forever. What I want is to respond with jump, but I can't figure out the language for it.
As I thought. Instead of jump gobbledegook (syntax error is because jump and gobbledegook are separate words) you need to use a single expression, it could be the python equivalent, wich If I remember correctly is:

Code: Select all

renpy.jump('gobbledegook')
So you can try and pass that as it is (wich may give syntax error, I'm not sure), or just pass the label name ('gobbledegook') and have the secondary screen jump to it like in my first code. I don't know if dictionaries are iterable but it is worth a shot.
The silent voice within one's heart whispers the most profound wisdom.

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

Re: How do I put items in a custom choice screen?

#15 Post by TellerFarsight »

That just skips the entire location_list screen and goes straight to the new label, somehow. I tried moving the new label somewhere else and it said the whole data list was undefined, because it was interrupted by renpy.jump("gobbledegook") and just went straight to the new label.

I tried using Jump("gobbledegook") instead and it responded with the in-game narrator saying as dialogue:
"<store.Jump object at 0x0893A450>"

I think the issue here is that we've already defined the response as a string

Code: Select all

label loop:
    $ txt = ui.interact()
    "[txt]"
    jump loop
but I don't know how to change it to something more general.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

Post Reply

Who is online

Users browsing this forum: No registered users