Function to close all screens once

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
renardjap
Regular
Posts: 75
Joined: Sun Aug 05, 2018 1:08 pm
Location: France ! Cocorico
Contact:

Function to close all screens once

#1 Post by renardjap » Mon Jun 29, 2020 11:28 am

Hello,
In my game, I use many screens. Sometimes, screens are opened and the user jump to another without closing the last screen... I would like to create a function to close all the screens except two (a custom menu interface and a screen who contains all the timers of the game.).
Maybe a python Function close_all_screens() with a loop who list all the screens except the menu and the timer screens.
I don't now how can I do this loop... How are stocked the screens in renpy to do a for loop ? (my screens are stocked in different files).

Someone has an idea to write this code ?

strayerror
Regular
Posts: 154
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Function to close all screens once

#2 Post by strayerror » Mon Jun 29, 2020 12:42 pm

By default all screens are placed on the screens layer by Ren'Py. The renpy.scene function is capable of clearing a layer. You can see where I'm going with this.

If you were to introduce a new layer to your game (in this example I'm going to refer to and name it persistent, but so long as you know what it is, it doesn't matter), and place the screens you wish to always remain on that layer (show screen xyz(_layer='persistent')) then leave all your remaining screens to display normally on the screens layer, you can clear all of your screens from the screens layer using renpy.scene(layer='screens').

Wow. That got wordy real fast at the end there! Still, hope that made some modicum of sense. There may be better ways to do this, but this seemed like a good option off the top of my head. Hope it's helpful!

P.S. Be aware that using this method you will not be able to hide your "persistent" screens using hide screen and will instead need to use the function call below. :)

Code: Select all

$ renpy.hide_screen('name of your screen', layer='persistent')

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]