Stopping the game from progressing to next label, unless a button is clicked

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
zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Stopping the game from progressing to next label, unless a button is clicked

#1 Post by zeroTheHero »

Simply, this is my code:

Code: Select all

screen choice:
	textbutton "Go North" action (Jump("North"))
	textbutton "Go South" action (Jump("South"))
	
label start:
	e "You stand at two crossroads"
	show screen choice
label North:
	e "You find Health"
label South:
	e "You find Wealth"
Right now, I directly go into label North even if I don't press any button and tap on screen. I tried to read how the choice menu in the screens.rpy file worked but I couldn't understand how they stopped this. This is probably a common question, but for the life of me idk what to type in the search bar to get an answer. A pointer would be greatly appreciated!
Last edited by zeroTheHero on Thu Nov 15, 2018 6:20 am, edited 1 time in total.

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

Re: Stopping the game from progressing to next label, unless a button is clicked

#2 Post by Enchant00 »

Use call screen choice instead of show screen.

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#3 Post by zeroTheHero »

Enchant00 wrote: Thu Nov 15, 2018 5:09 am Use call screen choice instead of show screen.
yes call works but I don't want the screen to disappear...also, I don't know how to explain my situation without putting everything here, so this might be a bit lengthy...
Simplifying a bit, I've made a function for dialogue as well as choice menu. It looks like this:

Code: Select all

default Choices=False

init python:
    yadj = ui.adjustment()
    def msg(msg, choice1=False, choice2=False,choice3=False):
            store.m_msg.append((msg,choice1,choice2,choice3))
            store.yadj.value = store.yadj.range+300
            renpy.restart_interaction()
            renpy.pause()
            
screen Part1:
    frame background Bak:
        frame background None :   
            viewport:
                yadjustment yadj
                vbox spacing 15:

                    for message in m_msg:
                        $msg, choice1, choice2, choice3 = message
                        if choice1:											
                              frame background Frame("gui/button/choice_background.png"):
                                    xysize(720,275)
                                    align (0.1, 0.1)
                                    vbox:
                                        yalign 0.5
                                        textbutton "%s"%(choice1) style "choicez" action NullAction(), SetScreenVariable("Choices", "Choice1_1")
                                        textbutton "%s"%(choice2) style "choicez" action NullAction(), SetScreenVariable("Choices", "Choice1_2")
                                showif Choices == "Choice1_1":
                                    screen shot:
                                        vbox:        
                                            text "You found health"      
                                showif Choices == "Choice1_2":
                                    screen lol:
                                        vbox:
                                            text "you found wealth"  

                                if Choices != False:
                                    screen cont:
                                        textbutton "Continue" action If(Choices=="Choice1_1", true=Call("CuteRoute"), false=Call("ninjaRoute")) 
			else:
                            hbox spacing 15:
                                button xalign xgn xmaximum 580 xpadding 20 ypadding 10 background Frame("box.png", 25, 25):
                                    text "%s"%(msg)
            
This is still kinda in the works, but if I were to emulate the above north-south example I'd write:

Code: Select all

	msg("You stand at two crossroads")
	msg("",choice1= "Go North", choice2 ="Go South")
And this leads to the problem I described in my first post.
Really sorry for troubling you guys :cry:
Thanks!

User avatar
Spoons
Newbie
Posts: 10
Joined: Tue Nov 13, 2018 4:39 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#4 Post by Spoons »

You could do it a couple of ways. Personally I'd just use a simple menu like:

Code: Select all

label adventure:
    "You stand at two crossroads, which one do you pick?"
    menu:
        "North":
            jump North
        "South":
            jump South

That's just using a simple menu though for your problem you could use "Return" instead of jump and set it up something like:

Code: Select all

   
label adventure:
    call screen textbutton_screen # Use call as when you use Return it'll store the input into _return
    screen textbutton_screen:
        vbox:
            xalign 0.5
            yalign 0.5
            spacing 5
            textbutton "North" action Return("North") 
            textbutton "South" action Return("South") 
    $ result = _return
    if result == "North":
        jump North
    if result == "South":
        jump South
label North:
    "You find Health"
    pause
label South:
    "You find Wealth"
    pause
Clicking anywhere other than the textbuttons does nothing.

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

Re: Stopping the game from progressing to next label, unless a button is clicked

#5 Post by Alex »

This might be useful for you - viewtopic.php?f=8&t=48359

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#6 Post by zeroTheHero »

Spoons wrote: Thu Nov 15, 2018 12:35 pm You could do it a couple of ways. Personally I'd just use a simple menu like:

Code: Select all

label adventure:
    "You stand at two crossroads, which one do you pick?"
    menu:
        "North":
            jump North
        "South":
            jump South

That's just using a simple menu though for your problem you could use "Return" instead of jump and set it up something like:

Code: Select all

   
label adventure:
    call screen textbutton_screen # Use call as when you use Return it'll store the input into _return
    screen textbutton_screen:
        vbox:
            xalign 0.5
            yalign 0.5
            spacing 5
            textbutton "North" action Return("North") 
            textbutton "South" action Return("South") 
    $ result = _return
    if result == "North":
        jump North
    if result == "South":
        jump South
label North:
    "You find Health"
    pause
label South:
    "You find Wealth"
    pause
Clicking anywhere other than the textbuttons does nothing.
Hey, thanks for the reply! Unfortunately this code doesn't work, it gives an error "jump is not a valid argument for vbox statement"

I changed the code a bit to:

Code: Select all

screen textbutton_screen:
    vbox:
        xalign 0.5
        yalign 0.5
        spacing 5
        textbutton "North" action Return("North") 
        textbutton "South" action Return("South") 
    $ result = _return
    if result == "North":
        vbox:
            textbutton "Continue" action(Jump("North"))
        # kinda like jump "North"
    if result == "South":
        vbox:
            textbutton "Continue" action(Jump("South"))
        # jump "South"

label adventure:
    call screen textbutton_screen # Use call as when you use Return it'll store the input into _return
    
label North:
    "You find Health"
    pause
label South:
    "You find Wealth"
    pause
This code runs, but not in the right way. First the plus: clicking anywhere apart from the textbuttons on screen does nothing, so this part works. However,

1)Pressing North or South textbutton doesn't show the "Continue" button. I reckoned using 'showif' instead of if would work but it doesn't.

2)With the above code, pressing either North or South button leads to the very next label irrespective of which button you press. So, both buttons go to label "North".

Thanks!

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#7 Post by zeroTheHero »

Alex wrote: Thu Nov 15, 2018 2:15 pm This might be useful for you - viewtopic.php?f=8&t=48359
Hey Alex, thanks for the reply! My problem is that the screen Choice is smaller than the other screens, so if I click outside screen Choice the game automatically proceeds to the next label without the player actually making a choice! Thanks for the link, it made my problem more clear to me :lol:

User avatar
Spoons
Newbie
Posts: 10
Joined: Tue Nov 13, 2018 4:39 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#8 Post by Spoons »

Hey, thanks for the reply! Unfortunately this code doesn't work, it gives an error "jump is not a valid argument for vbox statement"
Looks like you indented the sections a little too much.

Here is a screenshot of what it should look like (Obviously changed to fit your needs) but notice the $, if,elif and else are all under the test label not vbox.

Image

The else statement could probably not even be there as you can't click anything other than North or South making else a little pointless.


You might be getting the error because you're nesting this code into some other code which places it inside a vbox? Run by itself this code works fine from testing.

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#9 Post by zeroTheHero »

Spoons wrote: Fri Nov 16, 2018 4:05 am
Hey, thanks for the reply! Unfortunately this code doesn't work, it gives an error "jump is not a valid argument for vbox statement"
Looks like you indented the sections a little too much.

Here is a screenshot of what it should look like (Obviously changed to fit your needs) but notice the $, if,elif and else are all under the test label not vbox.

Image

The else statement could probably not even be there as you can't click anything other than North or South making else a little pointless.


You might be getting the error because you're nesting this code into some other code which places it inside a vbox? Run by itself this code works fine from testing.
Holy moly you're right! But how did this work?... Can you please tell me the difference between

Code: Select all

label start:          # Your code
   
label adventure:
    call screen textbutton_screen # Use call as when you use Return it'll store the input into _return
    screen textbutton_screen:
        vbox:
            xalign 0.5
            yalign 0.5
            spacing 5
            textbutton "North" action Return("North") 
            textbutton "South" action Return("South") 
    $ result = _return
    if result == "North":
        jump North
    if result == "South":
        jump South
label North:
    "You find Health"
    pause
label South:
    "You find Wealth"
    pause
and

Code: Select all

screen textbutton_screen:		# Just put these lines on top instead of beneath 'call screen textbutton_screen'
    vbox:
        xalign 0.5
        yalign 0.5
        spacing 5
        textbutton "North" action Return("North") 
        textbutton "South" action Return("South") 
$ result = _return
if result == "North":
    jump North
if result == "South":
    jump South
    
label start:
   
label adventure:
    call screen textbutton_screen # Use call as when you use Return it'll store the input into _return

label North:
    "You find Health"
    pause
label South:
    "You find Wealth"
    pause
The first one works, the second doesn't...
Thanks!

User avatar
Spoons
Newbie
Posts: 10
Joined: Tue Nov 13, 2018 4:39 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#10 Post by Spoons »

It's because it never gets to run the $,if section because it was Returned back to its position from where it was called from and obviously indenting them sections once would put them within the vbox which will throw you that error.

For example, simply moving the $,if sections under the adventure label and then adding return to north and south labels woulds fix that second bit of code. I've added comments to try explain it the best I could:

Code: Select all

screen textbutton_screen:
    vbox:
        xalign 0.5
        yalign 0.5
        spacing 5
        textbutton "North" action Return("North") 
        textbutton "South" action Return("South") 
$ result = _return                                            # 
if result == "North":                                         #
    jump North                                                 # Move these to the adventure label
if result == "South":                                         #
    jump South                                                 #
    
label start:
   
label adventure:
    call screen textbutton_screen 

label North:
    "You find Health"
    pause
                              # add return here (Or a jump depending on what you want to do. If you don't add anything, it'll just continue going down which in this case is label 
                              south.)
label South:
    "You find Wealth"
    pause
                              # add return here (Or a jump depending on what you want to do. If you don't add anything, it'll just continue with the code going down.)

I suck at explaining things, sorry. If you want to see how it's reading it, just use the interactive director (shift+d) in Ren'Py and you'll see it never even runs the $,if section because it gets Returned before it could.

That's how I understand it anyways and might not even be correct or probably confused the issue even more. I only started Ren'Py a couple days ago so sorry if my explaining or some wording is incorrect.

Hope this helps even a little, good luck!

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#11 Post by zeroTheHero »

Spoons wrote: Fri Nov 16, 2018 7:39 am It's because it never gets to run the $,if section because it was Returned back to its position from where it was called from and obviously indenting them sections once would put them within the vbox which will throw you that error.

For example, simply moving the $,if sections under the adventure label and then adding return to north and south labels woulds fix that second bit of code. I've added comments to try explain it the best I could:

Code: Select all

screen textbutton_screen:
    vbox:
        xalign 0.5
        yalign 0.5
        spacing 5
        textbutton "North" action Return("North") 
        textbutton "South" action Return("South") 
$ result = _return                                            # 
if result == "North":                                         #
    jump North                                                 # Move these to the adventure label
if result == "South":                                         #
    jump South                                                 #
    
label start:
   
label adventure:
    call screen textbutton_screen 

label North:
    "You find Health"
    pause
                              # add return here (Or a jump depending on what you want to do. If you don't add anything, it'll just continue going down which in this case is label 
                              south.)
label South:
    "You find Wealth"
    pause
                              # add return here (Or a jump depending on what you want to do. If you don't add anything, it'll just continue with the code going down.)

I suck at explaining things, sorry. If you want to see how it's reading it, just use the interactive director (shift+d) in Ren'Py and you'll see it never even runs the $,if section because it gets Returned before it could.

That's how I understand it anyways and might not even be correct or probably confused the issue even more. I only started Ren'Py a couple days ago so sorry if my explaining or some wording is incorrect.

Hope this helps even a little, good luck!
Are you kidding me YOU ARE THE GREATEST HOOMAN ALIVE!! Seriously, thank you so much for taking your time out to write this, it really helped fill out some gaps I didn't even realize I had. Like, I didn't even know what Return did or how to use it (cuz the docs didn't make much sense to a newb like me :P) but now I at least got a sense of what it does! A thousand thankies may not be enough, but take them! And a cookie! Cuz you deserve it m8 :lol:

PS do you perchance know a thread on lemma that explains _return/Return()? Cuz the docs make little sense to me rn :cry: How did you wrap your head around it? I'm probably gonna try banging my head (read experimenting) with Returns for a bit, but if there is a less painful way, pls lemme know.
Thanks, have a great day !

User avatar
Spoons
Newbie
Posts: 10
Joined: Tue Nov 13, 2018 4:39 am
Contact:

Re: Stopping the game from progressing to next label, unless a button is clicked

#12 Post by Spoons »

I doubt I could explain it any better than this page here https://www.renpy.org/doc/html/screens.html#call-screen i'm afraid. (Not sure if it's outdated or not, That's usually the biggest issue is finding up-to-date documentation.)
The call screen statement shows a screen, and then hides it again at the end of the current interaction. If the screen returns a value, then the value is placed in _return.

This can be used to display an imagemap. The imagemap can place a value into the _return variable using the Return() action, or can jump to a label using the Jump() action.
It just takes whatever you put in the Return() parameters and stores it into an _return variable from what I understand of it.

You could actually make it much smaller so instead of Return() put Jump() instead and delete all the $,if sections. Like this:

Code: Select all

screen textbutton_screen:
    vbox:
        xalign 0.5
        yalign 0.5
        spacing 5
        textbutton "North" action Jump("North")
        textbutton "South" action Jump("South")

label start:


label adventure:
    call screen textbutton_screen
	
label North:
    "This is north"
    return

label South:
    "This is south"
    return
That gives the same end results as the other code and is less messy without all that $,if section.

Post Reply

Who is online

Users browsing this forum: No registered users