[SOLVED]choice box

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
AoiMF
Newbie
Posts: 15
Joined: Sun Mar 31, 2019 2:39 am
Contact:

[SOLVED]choice box

#1 Post by AoiMF » Sat Jul 13, 2019 2:57 am

Hi, I'm asking a lot of questions recently.
I want choice boxs to be on the right and left.
If they were four, they would put two down on the left and right.
I do not know much about programming, so if you can give a simple explanation. Thankful :)
Last edited by AoiMF on Sun Jul 14, 2019 1:42 am, edited 1 time in total.

Crazy Li
Regular
Posts: 112
Joined: Fri Jan 03, 2014 3:35 pm
Contact:

Re: choice box

#2 Post by Crazy Li » Sat Jul 13, 2019 4:52 am

Hmm... I don't know for sure, but I assume you'll need to edit screens.rpy for this (or create your own screen for custom choice boxes and call that... but you said simple explanation and making your own custom screen isn't exactly simple :p )

My best guess is to search for the area that defines the Choice screen, approximately 200 lines in. If you were to change the existing

Code: Select all

    vbox:
        for i in items:
            textbutton i.caption action i.action
into

Code: Select all

    vbox:
        grid 2 2:
            for i in items:
                textbutton i.caption action i.action
It would in theory make 2 columns of choices... HOWEVER this would only work if you always use exactly 4 choices... any more or any less and it would surely give an error, so I'm positive that this is not the correct solution.

I'm not sure there's an actual "easy" way to do this. It probably takes a lot of fancy coding to determine how to lay it out based on the items pulled (so most likely the correct code actually goes after the "for i in items:" part)... but I'm not that good at Python to know what exactly you'd wanna do here. I'm sure someone will come along with the exact method that you can just copy and paste into your project though...

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

Re: choice box

#3 Post by Alex » Sat Jul 13, 2019 8:35 pm

As Crazy Li said, you need to modify choice screen in screens.rpy. Try it like

Code: Select all

screen choice(items):
    #style_prefix "choice"
    
    # let's make a grid of 2 columns
    $ rows, reminder = divmod(len(items), 2)
    if reminder > 0:
        $ rows += 1

    grid 2 rows spacing 10:
        align (0.5, 0.5)
        xfill True
        for ind, i in enumerate(items):
            textbutton i.caption action i.action:
                background Solid("#ccc")
                xminimum config.screen_width/3
                if ind%2 == 0:
                    xalign 0.1
                    text_xalign 0.1
                else:
                    xalign 0.9
                    text_xalign 0.9
                
        for n in range(2*rows-len(items)):
            null


label start:
    "..."
    menu:
        "Choice 1":
            pass
        "Choice 2":
            pass
        "Choice 3":
            pass
        "Choice 4":
            pass
        "Choice 5":
            pass
    "?!"

https://www.renpy.org/doc/html/screens.html#grid
https://www.renpy.org/doc/html/style_pr ... properties
https://www.renpy.org/doc/html/style_pr ... erty-xfill
https://www.renpy.org/doc/html/style_pr ... properties
https://www.renpy.org/doc/html/style_pr ... properties

User avatar
AoiMF
Newbie
Posts: 15
Joined: Sun Mar 31, 2019 2:39 am
Contact:

Re: choice box

#4 Post by AoiMF » Sun Jul 14, 2019 1:31 am

Crazy Li wrote:
Sat Jul 13, 2019 4:52 am
Hmm... I don't know for sure, but I assume you'll need to edit screens.rpy for this (or create your own screen for custom choice boxes and call that... but you said simple explanation and making your own custom screen isn't exactly simple :p )

My best guess is to search for the area that defines the Choice screen, approximately 200 lines in. If you were to change the existing

Code: Select all

    vbox:
        for i in items:
            textbutton i.caption action i.action
into

Code: Select all

    vbox:
        grid 2 2:
            for i in items:
                textbutton i.caption action i.action
It would in theory make 2 columns of choices... HOWEVER this would only work if you always use exactly 4 choices... any more or any less and it would surely give an error, so I'm positive that this is not the correct solution.

I'm not sure there's an actual "easy" way to do this. It probably takes a lot of fancy coding to determine how to lay it out based on the items pulled (so most likely the correct code actually goes after the "for i in items:" part)... but I'm not that good at Python to know what exactly you'd wanna do here. I'm sure someone will come along with the exact method that you can just copy and paste into your project though...
I wanted to work on two boxs, as you said, the choice screen is a good idea. thanks anyway :D

User avatar
AoiMF
Newbie
Posts: 15
Joined: Sun Mar 31, 2019 2:39 am
Contact:

Re: choice box

#5 Post by AoiMF » Sun Jul 14, 2019 1:33 am

Alex wrote:
Sat Jul 13, 2019 8:35 pm
As Crazy Li said, you need to modify choice screen in screens.rpy. Try it like

Code: Select all

screen choice(items):
    #style_prefix "choice"
    
    # let's make a grid of 2 columns
    $ rows, reminder = divmod(len(items), 2)
    if reminder > 0:
        $ rows += 1

    grid 2 rows spacing 10:
        align (0.5, 0.5)
        xfill True
        for ind, i in enumerate(items):
            textbutton i.caption action i.action:
                background Solid("#ccc")
                xminimum config.screen_width/3
                if ind%2 == 0:
                    xalign 0.1
                    text_xalign 0.1
                else:
                    xalign 0.9
                    text_xalign 0.9
                
        for n in range(2*rows-len(items)):
            null


label start:
    "..."
    menu:
        "Choice 1":
            pass
        "Choice 2":
            pass
        "Choice 3":
            pass
        "Choice 4":
            pass
        "Choice 5":
            pass
    "?!"

https://www.renpy.org/doc/html/screens.html#grid
https://www.renpy.org/doc/html/style_pr ... properties
https://www.renpy.org/doc/html/style_pr ... erty-xfill
https://www.renpy.org/doc/html/style_pr ... properties
https://www.renpy.org/doc/html/style_pr ... properties
Thank you, this is great. I'm sure to use this :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot], cexo, Ende