[SOLVED] Splitting up choice boxes vertically rather than horizontally?

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
sasquatchii
Miko-Class Veteran
Posts: 552
Joined: Fri Jul 04, 2014 7:48 am
Completed: A Day in the Life of a Slice of Bread
Deviantart: sasquatchix
Soundcloud: sasquatchii
itch: sasquatchii
Location: South Carolina
Contact:

[SOLVED] Splitting up choice boxes vertically rather than horizontally?

#1 Post by sasquatchii »

Hi, I have designed and unconventional choice box layout, and would like to split them up into columns of 3 rather than rows as is the default for Ren'Py.

Here is an example of the mockup I made & what I am trying to achieve:

Image

I understand how to customize Ren'Py textboxes, but I have no idea how to code it so that the textboxes are aligned the way they are in my mockup. Does anyone have any ideas for what the best way to do this might be?

Any help is always much appreciated!
Last edited by sasquatchii on Wed Oct 04, 2017 9:01 am, edited 1 time in total.
ImageImage

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#2 Post by RicharDann »

You might want to use a 3x2 grid.

https://www.renpy.org/doc/html/screens.html#grid
The most important step is always the next one.

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#3 Post by mikolajspy »

I didn't test it, but I think something like this might work:

Code: Select all

screen choice(items):
    $ verticalnb = 0
    $ horizontalnb = 0
    $ i = 1
    style_prefix "choice"

    while i < 6  #as long as we have menu options
    hbox: #make horizontal box
        while verticalnb <= 3: #did we reach 3 horizontal boxes?
            while horizontalnb <=2: #did we fill 2 vertical boxes?
                vbox: #do vertical box
                   textbutton i.caption action i.action #add button
                   $ i =+ 1 #increase counter
                $verticalbumber =+ 1 #move to next column
Probably also pack everything into 'frame' function and specify location and dimensions there.
https://www.renpy.org/doc/html/screens.html#frame
Or, if you will ALWAYS have 6 options, you might try "grid" function. I think it would be more coding to make it more scalabe, but it's also something worth looking into.
https://www.renpy.org/doc/html/screens.html#grid

User avatar
sasquatchii
Miko-Class Veteran
Posts: 552
Joined: Fri Jul 04, 2014 7:48 am
Completed: A Day in the Life of a Slice of Bread
Deviantart: sasquatchix
Soundcloud: sasquatchii
itch: sasquatchii
Location: South Carolina
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#4 Post by sasquatchii »

Mikola, thank you. When I tried your code I got this error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 212: u'while' is not a keyword argument or valid child for the screen statement.
    while i < 6  
         ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
ImageImage

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#5 Post by RicharDann »

sasquatchii wrote: Tue Oct 03, 2017 2:45 pm Mikola, thank you. When I tried your code I got this error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 212: u'while' is not a keyword argument or valid child for the screen statement.
    while i < 6  
         ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
I think that's because screens do not support while statement. Try replacing 'while' with 'if' instead. That said I hope I'm wrong but I think that code might not entirely work without a little editing.
The most important step is always the next one.

User avatar
sasquatchii
Miko-Class Veteran
Posts: 552
Joined: Fri Jul 04, 2014 7:48 am
Completed: A Day in the Life of a Slice of Bread
Deviantart: sasquatchix
Soundcloud: sasquatchii
itch: sasquatchii
Location: South Carolina
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#6 Post by sasquatchii »

I also tried the 3 x 2 grid using the code that Richar Dan suggested, but am stumped as to how to get the textbox features into the grid. Also, it's not always going to need to be a 2 x 3 grid - sometimes there will be 4 options, sometimes 2, sometimes 5, etc. Here's what I've got so far:

Image

The grid @ the top is text only. The choices @ the center are the actual choices & are functional and fully work (but they are not laid out how I'd like them to be - as shown by my earlier mockup.

I've also uploaded the game folder to google drive if anyone wants to crack it open and take a look: https://drive.google.com/open?id=0Bzpuc ... mJSYUIxd1U

Thank you Mikola & RicharDann for your help thus far! I really appreciate it.
ImageImage

User avatar
sasquatchii
Miko-Class Veteran
Posts: 552
Joined: Fri Jul 04, 2014 7:48 am
Completed: A Day in the Life of a Slice of Bread
Deviantart: sasquatchix
Soundcloud: sasquatchii
itch: sasquatchii
Location: South Carolina
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#7 Post by sasquatchii »

RicharDann wrote: Tue Oct 03, 2017 2:55 pm
sasquatchii wrote: Tue Oct 03, 2017 2:45 pm Mikola, thank you. When I tried your code I got this error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 212: u'while' is not a keyword argument or valid child for the screen statement.
    while i < 6  
         ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
I think that's because screens do not support while statement. Try replacing 'while' with 'if' instead. That said I hope I'm wrong but I think that code might not entirely work without a little editing.
Thank you! I tried 'if' instead and here's the error I got:

Code: Select all

[code]
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 211: reached end of line when expecting ':'.
    if i < 6  
              ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
So my guess is that's probably going to be way over my head, not really sure what to do with either of those. I'll keep tinkering with it and see what else I can do with the grid for now!
ImageImage

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#8 Post by mikolajspy »

Code: Select all

File "game/screens.rpy", line 211: reached end of line when expecting ':'.
    if i < 6  
              ^
The error even explains what's wrong, you're missing an ':' at the end, try this:

Code: Select all

if i < 6 :
  #.. rest of code
  
But honestly I think "if" statement is not good, since it's not repeating itself to fill scalable grid...

EDIT: I think I got this, still not tested:

Code: Select all

screen choice(items):
    style_prefix "choice"

    for i in items:  #as long as we have something in menu options
    hbox: #make horizontal box
        for vnb in range(1,3): #did we reach 3 horizontal boxes?
            for hnb in range(1,2): #did we fill 2 vertical boxes?
                vbox: #do vertical box
                   textbutton i.caption action i.action #add button
     
Still needs work, but I don't have time at the moment, but I think it's a good base.
Last edited by mikolajspy on Tue Oct 03, 2017 3:33 pm, edited 1 time in total.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#9 Post by RicharDann »

mikolajspy wrote: Tue Oct 03, 2017 3:14 pm But honestly I think "if" statement is not good, since it's not repeating itself to fill scalable grid...
You're right, I didn't realize it before. However I did test it right now and while didn't work, it seems like it's not supported by screens, oddly enough.

What sasquatchii could do is setup the screen so it checks how many choices there are, and change the layout accordingly. Something like:

Code: Select all

screen choice(items):

    style_prefix "choice"

    if len(items) == 6:  #If there are 6 choices, use a 3x2 grid
        grid 3 2:
            xalign .5 yalign .5
            for i in items:
                textbutton i.caption action i.action
                
    elif len(items) in range(1,3):
        vbox:
            xalign .5 yalign .5
            for i in items:
                textbutton i.caption action i.action
What's missing here is a way to lay out the choices when there are 4 and 5. With 4 we could use a 2x2 grid but for 5, I can't really think of anything right now. Hope someone does have a better solution.
The most important step is always the next one.

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#10 Post by mikolajspy »

I think something more scalable would be better than checking number of choices each time (what if there will be 8? 9? 22?).
For scalability I'd use my suggestion, I edited last post replacing "while" with "for x in range(X,Y)" if Ren'Py supports this Python expression in screens, that should work.
This expression should work almost as while and do the job.

I'd need more time to think about it, but probably checking lenght, then checking if it can be fit in square, and filling grid size with generated variables could also be interesting.
For numbers like 5, 7, the lower line could be centered somehow.

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#11 Post by Scribbles »

so this works... just looks awful lol

Code: Select all

screen choice(items):
    style_prefix "choice"
    $ x = 2
    $ y = (len(items) / 2)
            
    grid x y:
        xalign 0.5 
        yalign 0.5
        
        for i in items:
            textbutton i.caption action i.action
the buttons bleed out of the screen- there is probably a fix BUT i've gotta run > < I'll look it over more later :)

ETA: it crashes if the grid is "overfull", and probably has a ton of other errors I'll look at it more later!
Image - Image -Image

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#12 Post by Divona »

Here is my take using "vpgrid":

Code: Select all

screen choice(items):
    style_prefix "choice"

    vpgrid:
        cols 3
        spacing 40

        xalign 0.5
        yalign 0.8

        for i in items:
            textbutton i.caption action i.action
gui.rpy

Code: Select all

define gui.choice_button_width = 570
define gui.choice_button_text_idle_color = "#000000"
Attachments
4 choices
4 choices
6 choices
6 choices
Completed:
Image

User avatar
sasquatchii
Miko-Class Veteran
Posts: 552
Joined: Fri Jul 04, 2014 7:48 am
Completed: A Day in the Life of a Slice of Bread
Deviantart: sasquatchix
Soundcloud: sasquatchii
itch: sasquatchii
Location: South Carolina
Contact:

Re: Splitting up choice boxes vertically rather than horizontally?

#13 Post by sasquatchii »

Thank you both so much!! Both your solutions totally work, and I really appreciate all your help with this. You have saved me a ton of time, and I really appreciate it :) I doubt I would have been able to come up with this solution without your help!
ImageImage

Post Reply

Who is online

Users browsing this forum: Baidu [Spider]