How can I call screen from another screen?

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
Alex
Lemma-Class Veteran
Posts: 2374
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

How can I call screen from another screen?

#1 Post by Alex » Sun Sep 18, 2011 10:42 am

Hi, folks!
Now I'm playing with <input> function and stuck a bit...
I want to make a screen with button, and when player clicks this button an input screen appears, and button name will be replaced with typed text.
So, I made screen with button and made an input screen - the problem is that I don't understand how can I set the value of my variable, that represents the button name...(
I can use my input screen in regular script:

Code: Select all

$ my_button name_var = renpy.call_screen("my_input_screen")
but when I tried to use it as screen button action, I received an error
"Exception: ui.interact called with non-empty widget/layer stack. Did you forget a ui.close() somewhere?"
Also, I didn't found a SL action for screen calling (only <Show> and <Hide> actions)... :?
My code is:

Code: Select all

screen my_input_screen:
    frame:
        xalign my_x yalign my_y
        xminimum 500 xmaximum 500
        hbox:
            text "Some text:" yalign 0.5
            
            frame:
                background Solid("#000000")
                xminimum 400 xmaximum 400
                hbox:
                    input:
                        length 10
                        default my_def size 45 color "#c00000"

screen my_buttons:
    vbox:
        textbutton qq action SetVariable (   "qq", str( renpy.call_screen("my_input_screen", my_x=0.2, my_y=0.7, my_def="q") )    )
        textbutton "Return" action Hide("my_buttons")

# The game starts here.
label start:

    "..."
    $ qq = "q"
    $ ww = "w"

    $ some_var = renpy.call_screen("my_input_screen", my_x=0.2, my_y=0.7, my_def="q")  # this works fine
    "%(some_var)s"

    show screen my_buttons  # the button doesn't work as I want it to be
    "...."
So, how can I call a screen from another screen? Or maybe I'm doing it all wrong and there is a much more elegant way to make my "input system"?
Thanks in advance...))

User avatar
zorexx
Newbie
Posts: 23
Joined: Thu Jun 23, 2011 7:15 am
Contact:

Re: How can I call screen from another screen?

#2 Post by zorexx » Sun Sep 18, 2011 3:05 pm

Are you looking for:

Code: Select all

Show(your_screen)
?

http://www.renpy.org/doc/html/screen_actions.html


You can actually make your screens return a value, and do something based on that value:

Code: Select all

textbutton qq action Return(1)
textbutton "Return" action Return(0)
then to get the return value:

Code: Select all

result = renpy.call_screen("my_buttons")

if result == 1:
  renpy.call_screen("my_input_screen")

You can use the UI functions too:

Code: Select all

ui.textbutton(qq, clicked=ui.returns(1))
ui.textbutton("Return", clicked=ui.returns(0))

result = ui.interact()

if result == 1:
  renpy.call_screen("my_input_screen")

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

Re: How can I call screen from another screen?

#3 Post by Alex » Mon Sep 19, 2011 4:25 pm

zorexx wrote:Are you looking for:

Code: Select all

Show(your_screen)
?
Not quite... I was wondering if it is possible to call screen from another screen (seems like that it is not allowed).
You can actually make your screens return a value, and do something based on that value:

Code: Select all

textbutton qq action Return(1)
textbutton "Return" action Return(0)
then to get the return value:

Code: Select all

result = renpy.call_screen("my_buttons")

if result == 1:
  renpy.call_screen("my_input_screen")
Hmm, I didn't thought of it, thanks...))

So, I ended up with this code:

Code: Select all

screen my_screen:
    tag input_screen
    modal True
    
    frame:
        xalign my_x yalign my_y
        xminimum 500 xmaximum 500
        hbox:
            text "Some text:" yalign 0.5
            
            frame:
                background Solid("#000000")
                xminimum 400 xmaximum 400

                hbox:
                    input:
                        length 10
                        default my_def size 45 color "#c00000"

screen my_buttons:
    tag buttons_screen
    modal True
    vbox:
        textbutton ("%s" %(qq) )  action Return ("1")
        textbutton ("%s" %(ww) )  action Return ("2")
        textbutton "Return" action [Return ("none"), Hide("my_buttons"), Hide("my_screen")]

# The game starts here.
label start:

    e "You've created a new Ren'Py game."
    $ qq = "default1"
    $ ww = "default2"

label loop:
    show screen my_buttons
    $ res = ui.interact()
    if res == "1":
        $ qq = renpy.call_screen("my_screen", my_x=0.5, my_y=0.01, my_def=qq)
        jump loop
    elif res == "2":
        $ ww = renpy.call_screen("my_screen", my_x=0.5, my_y=0.05, my_def=ww)
        jump loop

    "qq = %(qq)s\nww = %(ww)s"

    return
Not elegant, but seems to work...

User avatar
wyverngem
Miko-Class Veteran
Posts: 610
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: How can I call screen from another screen?

#4 Post by wyverngem » Sun Nov 04, 2012 11:21 pm

Code: Select all

screen PersonalData:
    tag input_screen
    modal False
    imagemap:
        auto "pd_%s.png"
        hotspot (77, 169, 204, 48) action SetVariable('bday', 'Spring') # B-Day
        hotspot (77, 217, 204, 48) action SetVariable('bday', 'Summer')# B-Day
        hotspot (77, 268, 204, 48) action SetVariable('bday', 'Autumn')# B-Day
        hotspot (77, 316, 204, 48) action SetVariable('bday', 'Winter')# B-Day
        hotspot (68, 437, 61, 52) action SetVariable('bt', 'A')#Bloodtype
        hotspot (140, 437, 61, 52) action SetVariable('bt', 'B')#Bloodtype
        hotspot (218, 437, 61, 52) action SetVariable('bt', 'AB')#Bloodtype
        hotspot (302, 437, 61, 52) action SetVariable('bt', 'O')#Bloodtype
        hotspot (85, 574, 204, 48) action SetVariable('ft', 'Sweets')#Sweets
        hotspot (85, 622, 204, 48) action SetVariable('ft', 'Handmade')# Hand
        hotspot (85, 673, 204, 48) action SetVariable('ft', 'Sparkling')# Sparkling
        
    frame:
        xpos 115 ypos 25
        xminimum 500 xmaximum 500
        background None
        hbox:
            frame:
                background None
                xminimum 400 xmaximum 400

                hbox:
                    input:
                        length 7
                        default my_def size 35 color "#c00000"

init:
    $ bt = ""
    $ ft = ""
    $ bday = ""
    $ pname = ""
    $ n = DynamicCharacter("pname", color=(192, 64, 64, 255))
# The game starts here.
label start:

    n "Fill out this form. Love me."
    $ pname = renpy.call_screen("PersonalData", my_x=0.5, my_y=0.01, my_def=pname)
    if bday == "" or bt == "" or ft == "" or pname == "":
        "Please fill out the whole form."
        $ pname = renpy.call_screen("PersonalData", my_x=0.5, my_y=0.01, my_def=pname)
    $ pname = pname.strip()
    
    n "Birthday: [bday] Blood: [bt] Favorites: [ft]"

return
It's almost perfect, except if you hit enter when you put in the name you skip the rest of the form. Also is there a way to just use a confirm button instead of Enter?
Attachments
pd_selected_hover.png
pd_hover.png
pd_ground.png

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

Re: How can I call screen from another screen?

#5 Post by Alex » Mon Nov 05, 2012 12:01 am

You see, there should be two screens - your form and input screen. The trick is to place the last one over imagemap in proper position to simulate the field filling.

User avatar
wyverngem
Miko-Class Veteran
Posts: 610
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: How can I call screen from another screen?

#6 Post by wyverngem » Mon Nov 05, 2012 5:02 pm

Thanks, sorry about the miss post. ^^;

ReAnimator
Regular
Posts: 52
Joined: Mon Dec 16, 2013 1:00 pm
Contact:

Re: How can I call screen from another screen?

#7 Post by ReAnimator » Tue Jun 13, 2017 2:44 am

action Call("screen") is not yet implemented?
I find it rather useful but I couldn't find in the doc.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3645
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How can I call screen from another screen?

#8 Post by trooper6 » Tue Jun 13, 2017 12:57 pm

ReAnimator wrote:action Call("screen") is not yet implemented?
I find it rather useful but I couldn't find in the doc.
There is no Call screen action. I don't know if that will ever be implemented due to the ways screens work. Instead, consider Showing the second screen and having that second screen be modal True so that the user can only interact with that screen--but be sure to have a close button on that screen.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

ReAnimator
Regular
Posts: 52
Joined: Mon Dec 16, 2013 1:00 pm
Contact:

Re: How can I call screen from another screen?

#9 Post by ReAnimator » Tue Jun 13, 2017 3:14 pm

Hi, trooper6. Thanks for your response.
The problem I have is if the user activated Auto Forward the game would still progress while the screen is shown.
Calling screen pauses the game, right? I want that feature for maps and inventories, called from other screen.
While typing this I thought of toggling Auto Forward off in the screen if it's on but I still find it a bit odd way to work with.
I also find when you enter the game menu(which contains save, load, preferences) from the game, then return to the game, at that moment ATL doesn't function. An instant return. I think this is something to do with ShowMenu screen action. So I wanted to use regular Call screen action instead, if existed. Again workaround above could be used but Call screen action feels more natural to me.
Call screen action has some negative effect on the way screen works?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3645
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How can I call screen from another screen?

#10 Post by trooper6 » Tue Jun 13, 2017 3:39 pm

Calling the screen doesn't exactly pause the game. What is does is open a new context and wait until the context is resolved before resuming in the original context. That might seem like a pause, but it isn't the same sort of thing. And you can't call a new context from a new context...so you can't call a screen from a screen. Also, screens aren't the game, they are UI objects, so the Autoforward is going to keep going over screens, generally speaking.

If you want a button that calls a map or inventory, and you don't want the user to be able to click forward on the story while the map or inventory is showing, you make modal True on the map and inventory screens. That means that while that screen if visible the user won't be able to click forward. Make sure to have a close button on those screens or your user will never be able to get out of the screen.

I suppose you could try toggling autoforward off when those screens are visible. See if it works.

As for your ATL, leaving the game means you've interrupted it in the middle, when you come back it will be a bit off. But good practice involves always including starting positions in your ATL, that helps. So for example, instead of having an ATL that moves you left, create an ATL that starting at center, moves you left.

On the topic of ShowMenu, most of the time you won't need it. So I wouldn't really use it.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

ReAnimator
Regular
Posts: 52
Joined: Mon Dec 16, 2013 1:00 pm
Contact:

Re: How can I call screen from another screen?

#11 Post by ReAnimator » Tue Jun 13, 2017 8:39 pm

Thanks for useful tips!

The context concept is new to me. So ren'py allows only one new context at a time. Is there any reason to this? Or just happened to be like that?

Anyway I'll use show screen instead with modal feature as you say.

Thanks again.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3645
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How can I call screen from another screen?

#12 Post by trooper6 » Tue Jun 13, 2017 8:58 pm

ReAnimator wrote:Thanks for useful tips!

The context concept is new to me. So ren'py allows only one new context at a time. Is there any reason to this? Or just happened to be like that?

Anyway I'll use show screen instead with modal feature as you say.

Thanks again.
I'm not a big expert on this matter...I've got good coding chops, but I think you'd need to talk to someone with a bit more compsci theory. But I know there are problems with saving and loading and rollback when in different contexts...and there is also something about variables not being the same in different contexts.

So...I just avoid all of that.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Google [Bot], Gushi