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
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

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

#16 Post by DannyGMaster »

I think I got it, kinda. I modified Alex's code a little:

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:
                    if act.has_key("res"): #New
                        button:
                            text act["act_name"]
                            action Return(act["res"])
                        null height 5

                    elif act.has_key("jump"): #New
                        button:
                            text act["act_name"]
                            action Jump(act["jump"])
                        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:
    $ day0_1200 = [ {"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..."},]},
        {"place":"Place 3", "img":"pl_3", "actions_list":[{"act_name":"Look around", "res":"It's Place 3 here."}, {"act_name":"Naoya", "jump": 'naoya_01'},]}
        ]
    "..."
    show screen my_scr(day0_1200)
   
label day0_map1:
    window hide
    $ txt = ui.interact()
    "[txt]"
    jump day0_map1

label naoya_01:

    hide screen my_scr

    "Naoya challenges you to a battle."

    #The game goes on, loop has exited succesfully

my_2_scr (that should be the actions screen) now checks what does the key for each action is. If the key is "res",
it displays the corresponding dialogue. If the key is "jump", it jumps to the corresponding label, exiting the loop. If you want further behavior you can add more elifs and more keys with more values. I hope that made sense.

I'm still trying to figure out the multiple lines dialogue but I hope this solves the jumping issue.
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?

#17 Post by Alex »

This was just an example how things can be done. To make this code suit for your needs you should modify it (or may be you'll have the better idea how to arrange such screens).
So, if you want the action screen to disappear when action was chosen, just add an action to hide this screen to the list of button's actions

Code: Select all

action [Hide("my_2_scr"), Return(act["res"])]
In my code this screen does not hides to let player choose all actions one by one, but instead the list of actions hides, 'cause when the narration is shown clicking on button will hide the say box first and only the second click will activate action button (so it was just a design matter).
If you want to jump to different labels then set the "res" to be the name of the label to jump

Code: Select all

{"act_name":"Listen", "res":"label_name_for_this_action"}
And then in label loop you'll use the returned value to made an actual jump

Code: Select all

$ txt = ui.interact()
jump expression txt
# or alternatively
# $ renpy.jump(txt)

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?

#18 Post by Alex »

DannyGMaster wrote: I'm still trying to figure out the multiple lines dialogue but I hope this solves the jumping issue.
If you know that screen has returned a list of sentenses to show you can make it like

Code: Select all

screen scr_1(x):
    textbutton "Press!" action Return(x) align(0.5,0.5)
    
# The game starts here.
label start:
    $ my_list = ["Line 1", "Line 2", "Line 3"]
    "..."
    show screen scr_1(my_list)
    $ txt = ui.interact()
    while txt:
        $ line = txt[0]
        $ txt = txt[1:]
        "[line]"
    "Done"
You can use while-loop in ordinary Ren'Py script, and for-loop can only be used in python block. But you'll be unable to save game state in the middle of python block.

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?

#19 Post by TellerFarsight »

Gotcha. I kept trying to use

hide label_name
instead of
Hide("label_name")
gotta remember to use functions

I understand now.
So far, it looks like Danny's solution is taking care of everything I need. I can jump to a label that has multiple lines of dialogue, and then jump loop to go back, I can respond with a single line, or I can jump somewhere else to escape the loop. So this is just for my understanding.

I had a feeling it was something in the loop block that would solve this, but can you have a mixture of test responses and jump responses using a similar if/elif statement? And the while-loop that you wrote; can I use all of these things at the same time?
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?

#20 Post by Alex »

Well, Danny's code do jumps if they set in data list

Code: Select all

elif act.has_key("jump"): #New
    button:
        text act["act_name"]
        action Jump(act["jump"])
Isn't it enough?

Or do you mean that action should do both - show some text and jump away?
In that case make "res" to be a tuple of list of text lines and the name of label to jump to, like

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")
    
    
# 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.","Nothing special..."], None)}, {"act_name":"Listen", "res":(["It's quiet here.","Suddenly, I got a vision..."], "vision")},]},
        
        ]
    "..."
    show screen my_scr(my_data)
    
label loop:
    $ txt, lbl = ui.interact()
    while txt:
        $ line = txt[0]
        $ txt = txt[1:]
        "[line]"
    if lbl:
        jump expression lbl
    "Done"
    jump loop
    
label vision:
    "{i}~some creapy stuff~{/i}"
    "?"
    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?

#21 Post by TellerFarsight »

No, sorry, I meant using the code you suggested:

Code: Select all

$ txt = ui.interact()
jump expression txt
# or alternatively
# $ renpy.jump(txt)

#and
label loop:
    $ txt = ui.interact()
    ["txt"]
    jump loop
Can both of these be combined somehow if I decided to not use Danny's solution (that one works and it's what I'm using, I was just trying to understand the solution you suggested)
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?

#22 Post by Alex »

In post above "res":([text,text, etc.], lable_name)

Code: Select all

"res":(["It's quiet here.","Suddenly, I got a vision..."], "vision")
So, two variables can be set with "res"'s value returned

Code: Select all

$ txt, lbl = ui.interact()
txt would have value [text,text, etc.] and lbl - lable_name

Then the code checks the values of this variables and do some actions. If the value would be None then nothing will happend.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]