[Solved with a workaround] Issues returning to main menu from a screen using simple python and code within a label

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
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

[Solved with a workaround] Issues returning to main menu from a screen using simple python and code within a label

#1 Post by ComputerArt.Club »

To cut to the chase, I have an issue of a pop up menu in the main menu that has a problem, I need to click return multiple times to exit the pop up, and even then it goes to the game rather than the main menu. The reason for this I will explain below/

The main menu has a button that should open the Appstore/Playstore, but before that there is a parental gate with randomly generated math questions. The code for the question was done within a label and a screen as I couldn't find a way to do it purely with screens.

Code: Select all

screen navigation():
	imagebutton:
		action Jump ("gate")
		
init python:
    pg1 = renpy.random.randint(5, 6) #variables for the parental gate
    pg2 = renpy.random.randint(1, 3)
    pg3 = pg1 - pg2

label gate:
    $ result = _return
    call screen gate
    if result == pg3: #pg3 is a variable from the math question that relates to the parental gate
        call screen  thanks
    if result == "goback": #for some reason this requires two clicks and then it starts the game.
        return
        return
        
screen gate:        
            text "What is [pg1] - [pg2]"
            hbox:
                textbutton _("1") action Return(1) # sometimes I need to click the answers two times for this to work.
                # etc.
            textbutton _("Go Back") action Return("goback") #for some reason this requires two clicks and then it starts the game.
screen thanks:
    on "show" action OpenURL("blahblahblah")
    text "Thanks!"
    textbutton _("Go Back") action Return() # It seems that this does not always work.
Any ideas how I can make sure that my "go back" buttons return to the main menu instead of to the game? Also, so that it does not require multiple clicks.

Any suggestions? I assume that this problem has its root in the label.
Thank you for taking the time to read this far. :)
Last edited by ComputerArt.Club on Sun Apr 19, 2020 10:41 am, edited 2 times in total.

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

Re: Issues returning to main menu from a screen using simple python and code within a label

#2 Post by Alex »

Try to rethink this system...

Code: Select all

init python:
    pg1 = renpy.random.randint(5, 6) #variables for the parental gate
    pg2 = renpy.random.randint(1, 3)
    pg3 = pg1 - pg2
will run once on a game launch, so player could just click all the answers one by one to find the right one.

Code: Select all

label gate:
    $ result = _return
    call screen gate
change the order of lines, otherwise 'result' will have the value of previouse answer (or anything else if player click some...).

Try to use ShowMenu action to show screens from main menu (like it made for other menus) and set the 'menu' tag for that screens to make them behave like others.

And maybe something like this will work...

Code: Select all

screen gate_scr():
    tag menu
    default pg1 = renpy.random.randint(5, 6) #variables for the parental gate
    default pg2 = renpy.random.randint(1, 3)

    frame:
        align(0.5, 0.5)
        vbox:
            text "What is [pg1] - [pg2]?"
            null
            for i in range(10):
                textbutton "[i]":
                    if i == (pg1 - pg2):
                        action ShowMenu("thanks")
                    else:
                        action Return()
            null
            textbutton _("Go Back") action Return()
https://www.renpy.org/doc/html/screen_a ... nu-actions

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Issues returning to main menu from a screen using simple python and code within a label

#3 Post by ComputerArt.Club »

Alex wrote: Sat Apr 04, 2020 11:07 am Try to rethink this system...
Thanks for your message! I appreciate it!

Originally I had a different tag, changing the tag to menu (and making the submenu full screen rather than a pop up) solved one problem (go back buttons will work) and introduced a new one (link will not open).

When tag is changed to menu the following code doesn't work:

Code: Select all

on "show" action OpenURL(...)
This is actually the whole point of this parental gate, so that line is important.

If I remove the tag altogether or change to another tag then the go back buttons won't work.
:/

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Issues returning to main menu from a screen using simple python and code within a label

#4 Post by ComputerArt.Club »

I have found a workaround, I kept the menu tag so that return would work and then, since I could not get 'on show' to work when using the menu tag, I got rid of the thanks screen and used the text button to directly open the Appstore. Users can then use a separate return button when finished.

Thanks again for your assistance!

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

Re: Issues returning to main menu from a screen using simple python and code within a label

#5 Post by Alex »

ComputerArt.Club wrote: Fri Apr 17, 2020 11:49 am ...When tag is changed to menu the following code doesn't work:

Code: Select all

on "show" action OpenURL(...)
This is actually the whole point of this parental gate, so that line is important. ...
Sorry, for late reply, and you also can try

Code: Select all

timer 0.1 action OpenURL(...) repeat False

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Issues returning to main menu from a screen using simple python and code within a label

#6 Post by ComputerArt.Club »

Alex wrote: Sun Apr 19, 2020 12:12 pm
ComputerArt.Club wrote: Fri Apr 17, 2020 11:49 am ...When tag is changed to menu the following code doesn't work:

Code: Select all

on "show" action OpenURL(...)
This is actually the whole point of this parental gate, so that line is important. ...
Sorry, for late reply, and you also can try

Code: Select all

timer 0.1 action OpenURL(...) repeat False
Thanks again Alex! That also worked!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], trailsiderice