A button that alternately shows and hides a screen

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
DesertFox
Regular
Posts: 196
Joined: Sun Jul 28, 2013 1:29 pm
Completed: Over The Hills And Far Away
Projects: My Little Dictator
Organization: WarGirl Games
Contact:

A button that alternately shows and hides a screen

#1 Post by DesertFox » Mon Apr 21, 2014 5:55 pm

I'm trying to implement a button that when clicked once will show the quickmenu, and then when clicked again, will hide it.
What line of coding would I need for an imagebutton that hides and then shows another screen?

User avatar
SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: A button that alternately shows and hides a screen

#2 Post by SundownKid » Mon Apr 21, 2014 5:58 pm

You have to make it 2 buttons inside a screen with a conditional branch. One press of the button sets the variable like "button1hide" to "True" and another press sets it to false. The first button shows the screen and the 2nd hides it.

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: A button that alternately shows and hides a screen

#3 Post by Asceai » Mon Apr 21, 2014 6:02 pm

It doesn't have to be 2 buttons, and you don't necessarily need a separate variable:

action If(renpy.get_screen("myscreen"), Hide("myscreen"), Show("myscreen"))

Of course, if you do want to use a separate variable, I'd recommend using ToggleVariable so you don't need the conditional.

User avatar
DesertFox
Regular
Posts: 196
Joined: Sun Jul 28, 2013 1:29 pm
Completed: Over The Hills And Far Away
Projects: My Little Dictator
Organization: WarGirl Games
Contact:

Re: A button that alternately shows and hides a screen

#4 Post by DesertFox » Mon Apr 21, 2014 6:57 pm

Thank you, that works perfectly

Quick question - any way to apply a transition to the show and hide actions here?

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: A button that alternately shows and hides a screen

#5 Post by Asceai » Mon Apr 21, 2014 7:05 pm


Post Reply

Who is online

Users browsing this forum: Google [Bot], zyric