[Solved] Hiding multiple screens when switching locations

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
Uy27
Regular
Posts: 29
Joined: Wed Apr 04, 2018 2:07 am
Contact:

[Solved] Hiding multiple screens when switching locations

#1 Post by Uy27 »

Hi so I'm using demonangelz viewtopic.php?f=51&t=33333#p380743 navigation system.
Which means I can move to different rooms (screens) from all the locations. No problem there.

I then have different objects/persons that can be clicked on.
Example on code.

Code: Select all

label RoomA:
    if dayTime == 0:
        scene RoomADay
    if dayTime == 1:
        scene RoomADay
    if dayTime == 2:
        scene RoomADay
    if dayTime == 3:
        scene RoomADusk
    if dayTime ==4:
        scene roomANight

    show screen RoomAClick
return

screen RoomAClick:
    modal True
    imagebutton:
       idle "gui/roomClicks/bedNothing.png"
       hover "gui/roomClicks/bedHover.png"
       focus_mask True
       action Confirm("Sleep?", yes = Call("bedsleep2"))
    imagebutton:
       idle "gui/roomClicks/laptop.png"
       hover "gui/roomClicks/laptopHover.png"
       focus_mask True
       action ui.callsinnewcontext("...")
And then when switching rooms to example roomB or roomC you write hide screen RoomAClick etc.
Works as intended.
Now my problem is. This seems like it is extremely annoying once you get more rooms and more stuff to interact with.

So example 7 rooms. 10 different stuff to interact in one of the rooms. Which means that all 6 other rooms need to start with "hide screen bla bla" in all the rooms?
so 70 times its needed to write hide stuff. And that is just for 10 stuff in one room to interact with.

So basically I'm asking. Is there a good way to hide/close screens when switching to another screen, so you don't have to write hide screen in all the different locations?

Hope my question was clear enough.
Last edited by Uy27 on Sun May 27, 2018 1:50 pm, edited 1 time in total.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Hiding multiple screens when switching locations

#2 Post by kivik »

You can use the tag property for screens:

https://www.renpy.org/doc/html/screens. ... -statement

If all your screens share the same tag, then showing one will hide any other currently onscreen.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Hiding multiple screens when switching locations

#3 Post by Remix »

a) Use tags
Basically add " tag click_screen " to all the clickables, then " hide click_screen " will hide one no matter the actual screen names
Any tag used between screens basically groups them together as one under one name. Only one screen of a set tag can be shown at once so you might need more tag identifiers, e.g. " tag background_screen "

b) Use a label callback

Code: Select all

init python:

    def hide_those_screens( target_label, context ):
        renpy.hide_screen( "click_screen" )
        renpy.hide_screen( "background_screen" )

    config.label_callback = hide_those_screens
Frameworks & Scriptlets:

Uy27
Regular
Posts: 29
Joined: Wed Apr 04, 2018 2:07 am
Contact:

Re: Hiding multiple screens when switching locations

#4 Post by Uy27 »

Oh wow, I spent so long on searching how to do this and I never ended up on tags.
I need to up my search game haha.

Thank you a ton kivik for taking your time to help me. It's working awesome now.

*Edit*

Thank you too Remix! I will try both solutions and see which works the best. Thanks for taking your time on this :D

Post Reply

Who is online

Users browsing this forum: Andredron, Majestic-12 [Bot]