How to jump to the title screen in Renpy


You just put "return" at the end of a script.

But that only works if you are completely sure there's nothing in the Event Stack. 

What's an Event Stack?

An Event Stack is where a Renpy game saves from where you called it when you use the "call" statement.  So, every time you use the "return" statement for end an script, Renpy is going to get the last thing the system put on the stack automatically, and jump to that position. If the stack is empty, the system goes to the Title Screen. 

When you use the "jump" statement, Renpy does not add from where you called "jump", but does not clean the Stack. Meaning, if in the stack is still the position from a call statement you forgot from very far the script, you are going to go to that position. 

And while I do understand I should know when the Event Stack is clean or not, sometimes I need a hack to fix things. And here's goes "renpy.set_return_stack(stack)". 

You can set the return stack to anything you want, to the point that you can give it a list with label names and that's good enough. 

Ahhh... but first. 

Renpy is a framework over Python, and in Python, a stack is a data structure implemented using lists. Here's more detail about that. Meaning that, in python, you can use a list as a stack. And this is basically what Renpy does. 

The idea here is: If I'm calling the "return" statement so I can jump to the Title Screen, I need to be 100% sure the Event Stack is an empty list.  So, I do this:

$ renpy.set_return_stack([])
return

I have to put the "$" escape sign because I'm using the Renpy object directly. The "[]" is the list itself. So, like, if you add "['label1']" when the return statement is called is going to go to the label1 label. And if I add ['label1', 'label2']  the return statement is going to go to the label2 label. But since the list I'm setting the event stack to use is empty, the return statement is going to jump to the title screen. 

Here's the page of the Renpy doc for more labels! It's giving me ideas, and considering this is a Undertale Fan Game, I better use some of those ideas. :D

Get User Interface

Leave a comment

Log in with itch.io to leave a comment.