Tried to have randomized styles

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
Sehaf
Regular
Posts: 58
Joined: Thu Feb 25, 2010 9:22 pm
Projects: Demon Lord & Yuki Academy
Deviantart: Sehad
Location: Sweden
Contact:

Tried to have randomized styles

#1 Post by Sehaf » Thu Jan 30, 2020 11:39 am

So, Tried to do some heavy experimenting with the choice meny, this is what I made.

Code: Select all

screen choice(items):

    frame:
        style "other_frame"
        xalign 0.5
        yalign 0.5
    
        hbox:
            xmaximum 650
            
            viewport id "men_bar":
                xalign 0.5 yalign 0.5
                xysize (600, 400) #Could shorten hight as it not to clip in the image
                
                #scrollbars "vertical" style "viewport_menu"
                #spacing 5
                
                draggable True
                #edgescroll (100, 500)
                mousewheel True
                arrowkeys True
                
                window:
                    at choice_menu_transition ###Added as test to see if I can transition them in and out?
                    style "menu_window"
                    #xalign 0.5
                    yalign 0.5
                    
                    vbox:
                        style "menu"
                        spacing 2
                        
                        for caption, action, chosen in items:
                    
                            if action:
                        
                                #This is the test code
                                $ randomSTYLE = renpy.random.randint(1, 3)
                                if randomSTYLE == 1:
                                    button:
                                        action action
                                        style "menu_choice_button"
                            
                                        text caption style "menu_choice"
                                        
                                elif randomSTYLE == 2:
                                    button:
                                        action action
                                        style "button_test2"
                            
                                        text caption style "button_text_test2"
                                elif randomSTYLE == 3:
                                    button:
                                        action action
                                        style "button_test3"
                            
                                        text caption style "button_text_test3"
                                    
#                                button:
#                                    action action
#                                    style "menu_choice_button"
#                            
#                                    text caption style "menu_choice"
                            
                            else:
                                text caption style "menu_caption"

                    
                        
            bar value YScrollValue("men_bar") ymaximum 400 style "viewport_menu"

And while it technickly works, it jumps around, so that the styles shift around while I'm reading the options. The idea was simply to have not all buttons look statickly the same. Any Ideas????
I'm a GameMaker!
My Portfolio: http://www.bluepipestudio.com

User avatar
namastaii
Eileen-Class Veteran
Posts: 1312
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Tried to have randomized styles

#2 Post by namastaii » Thu Jan 30, 2020 2:47 pm

What happens if you take out the "if action" line (and fix the code's indentation after that)?

philat
Eileen-Class Veteran
Posts: 1730
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Tried to have randomized styles

#3 Post by philat » Thu Jan 30, 2020 10:11 pm

Handling randomization in screens is more of a headache than it's probably worth, tbh. Pulling the randomization OUT of the screen is the easier solution. Didn't run this, but it should work. *shrug*

Code: Select all

screen choice(items, randomSTYLE==1): # note the keyword argument passed into the screen (or if not passed in, set to 1 by default)

    frame:
        style "other_frame"
        xalign 0.5
        yalign 0.5
    
        hbox:
            xmaximum 650
            
            viewport id "men_bar":
                xalign 0.5 yalign 0.5
                xysize (600, 400) #Could shorten hight as it not to clip in the image
                
                #scrollbars "vertical" style "viewport_menu"
                #spacing 5
                
                draggable True
                #edgescroll (100, 500)
                mousewheel True
                arrowkeys True
                
                window:
                    at choice_menu_transition ###Added as test to see if I can transition them in and out?
                    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"
                                    
                                    if randomSTYLE == 1:
                                        text caption style "menu_choice"
                                    elif randomSTYLE == 2:
                                        text caption style "button_text_test2"
                                    elif randomSTYLE == 3:
                                        text caption style "button_text_test3"
                            else:
                                text caption style "menu_caption"
                    
                        
            bar value YScrollValue("men_bar") ymaximum 400 style "viewport_menu"

label start:
    menu (randomSTYLE = renpy.random.randint(1,3)): # menu arguments: https://www.renpy.org/doc/html/menus.html#menu-arguments
        "Caption"
        "Option1":
            pass
        "Option2":
            pass

Post Reply

Who is online

Users browsing this forum: Google [Bot]