[SOLVED] Jumping to another screen via screen conditional

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
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

[SOLVED] Jumping to another screen via screen conditional

#1 Post by Kinmoku »

Hi all,

On my main menu, I have a conditional which, if you've played the game once, pops up and congratulates you. Originally, I had this code below, which worked but the "okay" button would occasionally not focus by default and wouldn't even highlight if I pressed left, right, up, down on the controller (FYI this is for a console port).

This is my old code:

Code: Select all

screen main_menu():
    add MouseHiderDisplayable() size (1,1)
    tag menu
    
    if len(persistent.endings) == 1:
        window:
        add "mainmenubg"
        
        hbox:
            add "images/popup.png" xanchor 0.0 yanchor 0 xpos 410 ypos 200

        vbox:
            yanchor 0
            xanchor 0.5
            ypos 350
            xalign 0.5
            xmaximum 1000
            ymaximum 350

            xfill True
            spacing 25

            label _("Congratulations! #etc"):
                text_style "yesno_label_text"
                xalign 0.5
                yalign 0.5

            hbox:
                style "menu"
                xalign 0.5
                ypos 250
                spacing 70
            
            button:
                action [Return(), AddToSet(persistent.endings, 1)] default True
                style "menu_choice_button"
                text _("Okay") style "menu_choice"
    
So I thought if I made the popup its own screen and added "modal True", it would fix the issue. (The main menu also acts incorrectly on controller, thinking there is another button above it too).

Here's my new code, but unfortunately it doesn't work:

Code: Select all

screen main_menu():
    add MouseHiderDisplayable() size (1,1)
    tag menu
    
    if len(persistent.endings) == 1:
        use firstplaythroughpopup
        
        
        ### rest of menu
        
screen firstplaythroughpopup:
    add MouseHiderDisplayable() size (1,1)
    modal True
  
    window:
        add "mainmenubg"
        
    hbox:
        add "images/popup.png" xanchor 0.0 yanchor 0 xpos 410 ypos 200

    vbox:
        yanchor 0
        xanchor 0.5
        ypos 350
        xalign 0.5
        xmaximum 1000
        ymaximum 350

        xfill True
        spacing 25
        
        label _("Congratulations! #etc"):
            text_style "yesno_label_text"
            xalign 0.5
            yalign 0.5

        hbox:
            style "menu"
            xalign 0.5
            ypos 250
            spacing 70
            
            button:
                action [Return(), AddToSet(persistent.endings, 1)] default True
                style "menu_choice_button"
                text _("Okay") style "menu_choice"
I have tried all kind of things instead of "use". Show, call, action etc... but without a button, I don't know how to make one screen go to another via conditionals. What am I missing? It makes sense "use" doesn't work, as I'm telling it to go to another screen.
Last edited by Kinmoku on Thu Aug 01, 2019 10:19 am, edited 1 time in total.

User avatar
Enchant00
Regular
Posts: 136
Joined: Tue Jan 12, 2016 1:17 am
Contact:

Re: Jumping to another screen via screen conditional

#2 Post by Enchant00 »

Maybe you can try the on "show: for screen menu with a one screen action If conditional. However, there seems to be an interesting thing in the screens documentation of the command showif https://www.renpy.org/doc/html/screens. ... -statement. I never tested it so give this a shot.

So try the following:

Code: Select all

screen main_menu():
    add MouseHiderDisplayable() size (1,1)
    tag menu
    
    showif len(persistent.endings) == 1:
        use firstplaythroughpopup
This is another option:

Code: Select all

screen main_menu():
    add MouseHiderDisplayable() size (1,1)
    tag menu
    on "show" action If(len(persistent.endings) == 1, Show(firstplaythroughpopup), NullAction())

If that doesn't work, it's possible that the error might be from the persistent variable. You can try creating a variable inside the screen that is the length of your endings and instead doing a check with said variable. If it doesn't show, it's possible that the persistent variable may not b updating at all. To be honest, I'm grasping at straws here since your code should work.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Jumping to another screen via screen conditional

#3 Post by Kinmoku »

Hey I really appreciate your help :) Unfortunately, I still can't get it to work.

I tried your code and added "" to the screen name but it didn't work, so I tried a few other things which didn't help either :( Anyway, here's my current code:

Code: Select all

    on "show" action If(len(persistent.endings) == 1, true = Show("firstplaythroughpopup"), false = None)
What's happening is when I click "Okay" on the screen to dismiss the message, it stays on the screen and the main menu doesn't show. I tried changing "Return()" on the button to "MainMenu()" and "Show("main_menu")" but they didn't help either.

As for "showif", this completely ignored the conditional and never showed the popup.

I don't think it's a problem with "if len(persistent.endings) == 1:" as I use this a few times and not had any difficulty.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Jumping to another screen via screen conditional

#4 Post by Kinmoku »

An update. I went back to using if and else:

Code: Select all

    if len(persistent.endings) == 1:
        on "show" action Show("firstplaythroughpopup")
        
    else:
        window:
            style "mm_root"
        hbox:
            spacing 50
            xalign 0.5
            ypos 920
            
            button default True:
                style "mainmenu_choice_button"
                text _("Start Game") style "mainmenu_choice"
                action Start()
                
            button:
                style "mainmenu_choice_button"
                text _("Load Game") style "mainmenu_choice"
                action ShowMenu("load")
                
            button:
                style "mainmenu_choice_button"
                text _("Settings") style "mainmenu_choice"
                action ShowMenu("preferences")
                
            if not persistent.endings:
                button:
                    style "grey_choice_button"
                    text _("Gallery") style "mainmenu_choice"
                    action Show("ok_prompt")
                    
            else:
                button:
                    style "mainmenu_choice_button"
                    text _("Gallery") style "mainmenu_choice"
                    action [ShowMenu("gallerybg"), ShowMenu("gallerypopup")]
        
But the issue with the menus didn't fix, so I changed my "okay" button to hide the firstplaythough screen and it seems to work on all endings!

Code: Select all

        hbox:
            style "menu"
            xalign 0.5
            ypos 250
            spacing 70
            
            button:
                action [Return(), AddToSet(persistent.endings, 1), Hide("firstplaythroughpopup")] default True
                style "menu_choice_button"
                text _("Okay") style "menu_choice"
Thanks for helping me figure it out :)

Post Reply

Who is online

Users browsing this forum: Google [Bot]