[Solved!] Using call and return statements

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
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

[Solved!] Using call and return statements

#1 Post by yuucie » Mon Jun 30, 2014 12:35 am

I'm trying to use call and return statements, and been reading up the renpy label and control flow section. However, I'm having trouble understanding it. So far, I understand that when you call something, it adds to a call stack somewhere, and return would return to the items in the call stack.

This is what I have so far:

Code: Select all

label town:

call screen townmap
    
label parkprompt:
        
$layout.yesno_screen("Go to the Park?", yes=Jump("park"), no=return())
$ renpy.pause()

label park:

"You go to the park."
# rest of game
    
I was hoping that by calling the screen townmap, it would add it to a call stack somewhere, and that by hitting no would return to the townmap. However, the return() command seems to go straight to the rest of the game under the label park. I'm confused as to how to correctly use call statements, and reading the cookbook doesn't seem to clear anything up. Help would be greatly appreciated!
Last edited by yuucie on Mon Jun 30, 2014 1:18 am, edited 1 time in total.

User avatar
ArachneJericho
Regular
Posts: 196
Joined: Sun Jun 22, 2014 2:04 am
Projects: Kaguya Hime
Tumblr: mousedeerproductions
Location: Seattle, WA, USA
Contact:

Re: Using call and return statements in yes/no prompts

#2 Post by ArachneJericho » Mon Jun 30, 2014 12:36 am

I'm very confused by the lack of indentation. Is there supposed to be some?

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using call and return statements in yes/no prompts

#3 Post by yuucie » Mon Jun 30, 2014 12:43 am

Ah, by calling the screen townmap, I'm calling up an imagemap (therefore the hotspots there lead to the labels parkprompt and so forth). Since the imagemap called the labels itself, I didn't indent the labels under the call statement...is that what you meant? Otherwise, there is the normal 4 space indentation, but none of the statements are indented under each other. (I'm starting to feel that's where the problem is, haha...)

User avatar
Ran08
Miko-Class Veteran
Posts: 737
Joined: Tue Jun 12, 2012 1:17 am
Completed: https://ran.itch.io/
Projects: Fate's Cafe
Tumblr: otometwist
Skype: @otomeran
itch: ran
Location: Manila
Contact:

Re: Using call and return statements in yes/no prompts

#4 Post by Ran08 » Mon Jun 30, 2014 12:56 am

Hmm, I don't really use yes or no prompts... hahaha. :) But I usually use call when I still want to return, and I use jump when I want to stay there. :D

However, I too, am confused by the indentation. :o Is it... supposed to be that way? I thought the rest of the code was supposed to be under the call screen townmap...

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using call and return statements in yes/no prompts

#5 Post by yuucie » Mon Jun 30, 2014 1:04 am

Ahh okay, since indentation seems to be a problem, here's a direct copy paste of my code:

Code: Select all

label start:
    #start of my game etc, to the point where i bring up the yes/no prompt window and start jumping and calling

    "I decided to go..."
    
    window hide
    
    $ renpy.pause(0.8, hard='True')
    
    jump town ###The reason why I'm not calling the screen townmap here is because I don't want the background image to change during this transition. In the game, the map is already opened, but just as a background image. I want the game to phase into the map as an imagemap at this point, which is why I'm using a jump here

label town:
    call screen townmap
    #This is an imagemap. I had already defined the imagemap beforehand, and the hotspots there were coded Jump("parkprompt") which could be the problem, since return statements don't work with Jump. I think I need to change this to Call, but Call("parkprompt") doesn't seem to be working.
    
label parkprompt:
    $layout.yesno_screen("Go to the Park?", yes=Jump("park"), no=Return())
    $ renpy.pause()
    
    return
    
label park:
    $ _window_during_transitions = True
    "I went to the park."
    
    return
I didn't indent anything under the call statement, as the screen townmap is an imagemap and has hotspots that jumped to places already. I think the coded hotspots might be the problem since they use Jump statements (which doesn't add to callstacks? maybe)?
Last edited by yuucie on Mon Jun 30, 2014 1:07 am, edited 1 time in total.

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Using call and return statements in yes/no prompts

#6 Post by Asceai » Mon Jun 30, 2014 1:07 am

There's a call stack, but it's only for subroutines (for simplicity I'm ignoring Python's call stack). That is, 'call (label)'. Despite the similar name and the fact that return is involved, it has nothing to do with 'call screen (screen name)' Call screen merely interrupts the control flow in renpy script - you can resume that with Return() or you can use Jump(), but either of them end the screen.

So, no. You have to jump back to town in your yesno prompt.

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using call and return statements in yes/no prompts

#7 Post by yuucie » Mon Jun 30, 2014 1:10 am

Asceai wrote:There's a call stack, but it's only for subroutines (for simplicity I'm ignoring Python's call stack). That is, 'call (label)'. Despite the similar name and the fact that return is involved, it has nothing to do with 'call screen (screen name)' Call screen merely interrupts the control flow in renpy script - you can resume that with Return() or you can use Jump(), but either of them end the screen.

So, no. You have to jump back to town in your yesno prompt.
Ahh that makes sense. Thanks for explaining to me! Is there a way to disable Jump transitions then? I had screen transitions set to fade in my options.rpy, which causes the screen to fade when I hit no. I just want transitions disabled for this particular screen, but not throughout my entire game. Nevermind, changed yesno window transition in options.rpy to dissolve instead of fade, which fixed the transition problem.

Thanks so much for all the help!
Last edited by yuucie on Mon Jun 30, 2014 1:13 am, edited 1 time in total.

User avatar
Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Using call and return statements in yes/no prompts

#8 Post by Valmoer » Mon Jun 30, 2014 1:12 am

A few details:
  • Return() doesn't do what return does, it sets up the return value of the screen and closes the screen.
  • call screen, as opposed to call label_name doesn't actually put stuff on the stack, or, if it does, it pops them as a matter of self-clean up.
To convince you, please try this code : you'll see, when you reach label parkprompt:, that the stack size still is 0. (Normally :? )

Code: Select all

label town:
    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : Beginning, stack_size should be 0 ? The current callstack size is [callstack_size]."

    call screen townmap

    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : Do I ever return there ? The current callstack size is [callstack_size]."
   
label parkprompt:
       
    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : I supposedly jumped to there from the townmap. The current callstack size is [callstack_size]."

    $ layout.yesno_screen("Go to the Park?", yes=Jump("park"), no=Return())
    $ renpy.pause()

    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : I'm never supposedly to be here. The current callstack size is [callstack_size]."

label park:

    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : I should have jumped from the yes/no screen. The current callstack size is [callstack_size]."
    "DEBUG : If the callstack size, [callstack_size], is > 0, I might unadvertantly -return- to a previous townmap call."

    "You go to the park."
    # rest of game
    
EDIT: Drat! Snip'd :D

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using call and return statements in yes/no prompts

#9 Post by yuucie » Mon Jun 30, 2014 1:15 am

Valmoer wrote:A few details:
  • Return() doesn't do what return does, it sets up the return value of the screen and closes the screen.
  • call screen, as opposed to call label_name doesn't actually put stuff on the stack, or, if it does, it pops them as a matter of self-clean up.
To convince you, please try this code : you'll see, when you reach label parkprompt:, that the stack size still is 0. (Normally :? )

Code: Select all

label town:
    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : Beginning, stack_size should be 0 ? The current callstack size is [callstack_size]."

    call screen townmap

    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : Do I ever return there ? The current callstack size is [callstack_size]."
   
label parkprompt:
       
    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : I supposedly jumped to there from the townmap. The current callstack size is [callstack_size]."

    $ layout.yesno_screen("Go to the Park?", yes=Jump("park"), no=Return())
    $ renpy.pause()

    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : I'm never supposedly to be here. The current callstack size is [callstack_size]."

label park:

    $ callstack_size = renpy.call_stack_depth()
    "DEBUG : I should have jumped from the yes/no screen. The current callstack size is [callstack_size]."
    "DEBUG : If the callstack size, [callstack_size], is > 0, I might unadvertantly -return- to a previous townmap call."

    "You go to the park."
    # rest of game
    
EDIT: Drat! Snip'd :D
Wow thanks so much for taking the time to write this code!! I will run it anyway just for the sake of better understanding the call/return statements. Thanks so much!

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Using call and return statements in yes/no prompts

#10 Post by Asceai » Mon Jun 30, 2014 1:15 am

yuucie wrote:I had screen transitions set to fade in my options.rpy.
What are screen transitions? There is no config.screen_transition so I don't know what you set to fade.

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using call and return statements in yes/no prompts

#11 Post by yuucie » Mon Jun 30, 2014 1:20 am

Asceai wrote:
What are screen transitions? There is no config.screen_transition so I don't know what you set to fade.
The one I mistook was

Code: Select all

config.intra_transition = dissolve
, which isn't actually screen transitions as you said! I realized what I needed was

Code: Select all

config.exit_yesno_transition = dissolve
. Thanks!

Post Reply

Who is online

Users browsing this forum: Alex, EOWNERDEAD