Finding out which scene is currently active

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
nyankun
Newbie
Posts: 2
Joined: Wed Jan 08, 2020 6:36 am
Contact:

Finding out which scene is currently active

#1 Post by nyankun »

Hello! :)
I was wondering if there was a way to find out which scene is currently active at any given moment. I'm making an adventure game where the player moves around a series of rooms, each room being a distinct scene, with its objects, characters, etc and it would be great if I could call the appropriate navigation/objects screen semi-automatically.

My current implementation is something like this:

Code: Select all

label room1:
    scene room1
    show screen navigation("room1")
    show screen objects("room1")
    call screen scrsetup #for inventory, etc.

screen objects(room):
    if(room == "room1"):
         ...imagebuttons, etc...
    if(room == "room2"):
         ...imagebuttons, etc...


which works, but I feel it's error-prone. I would be awesome if I could implement it like this (ideally with a function):

Code: Select all

label room1:
    scene room1
    show screen navigation()
    show screen objects()
    call screen scrsetup #for inventory, etc.
    
screen objects():
    if(renpy.currentscene == "room1"):
        ...imagebuttons, etc...
    if(renpy.currentscene == "room2"):
        ...imagebuttons, etc...
Any way to do this? Any suggestions welcome :)

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Finding out which scene is currently active

#2 Post by philat »

You can find a few by searching the forums for current label, etc.

That said, I previously made similar games with the below setup (conceptually) which worked fine for me.

Code: Select all

default lastscreen = "room1"

screen room1:
    on "show" action SetVariable("lastscreen", "room1")
    ... imagebuttons etc
    use navigation("room1")
    use scrsetup

screen room2:
    on "show" action SetVariable("lastscreen", "room2")
    ... imagebuttons etc
    use navigation("room2")
    use scrsetup

label room1:
    scene room1
    jump set_screen

label room2:
    scene room2
    jump set_screen

label set_screen:
    $ renpy.call_screen(lastscreen")

User avatar
nyankun
Newbie
Posts: 2
Joined: Wed Jan 08, 2020 6:36 am
Contact:

Re: Finding out which scene is currently active

#3 Post by nyankun »

philat wrote: Thu Jan 09, 2020 9:42 am

Code: Select all

 on "show" action SetVariable("lastscreen", "room1")
That's clever! I didn't know you could run actions as soon as screens are shown, this definitely opens up several possibilities, thanks a lot! :mrgreen:

Post Reply

Who is online

Users browsing this forum: Google [Bot]