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.
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.
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.
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...)
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.
However, I too, am confused by the indentation. Is it... supposed to be that way? I thought the rest of the code was supposed to be under the call screen townmap...
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.
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.
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.
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
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
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!