Is that possible to hide/unhide textbutton?

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
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Is that possible to hide/unhide textbutton?

#1 Post by iDweadith »

So, I want to hide a single textbutton when I click on it, but I don't know how! If I hide screens I will hide all buttons, while I wanna hide just one button that is the one clicked



Something like: when click on the button "open" it dissappear and another texbutton named "close" appears

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Is that possible to hide/unhide textbutton?

#2 Post by rayminator »

something like this.. this is what I'm using but I got from someone else I'm just using it

Code: Select all

init 1:
    $ mod_show = False
    $ mod_button_show = True

screen cheat:


    if mod_button_show:
        if renpy.loadable("cheatmod.rpy"):
            if mod_show == False:
                imagebutton xalign 0.10 ypos 0.02:
                    idle ("enter_mod_idle")
                    hover ("enter_mod_hover")
                    action [ Show("more_cheats"), SetVariable("mod_show", True)]
            else:
                imagebutton xalign 0.10 ypos 0.02:
                    idle ("exit_mod_idle")
                    hover ("exit_mod_hover")
                    if mod_show == True:
                        action [ Hide("more_cheats"), SetVariable("mod_show", False)]

style show_mod_button:
    size 42
    #bold True
    color "#1DDB16" # E60000
    hover_color "#d94c3a"
    outlines [(3, "#222222", 0, 0)]

style hide_mod_button:
    size 42
    #bold True
    color "#E60000" # E60000
    hover_color "#d94c3a"
    outlines [(3, "#222222", 0, 0)]

style ds_mod_style_close_button:
    size 40
    #bold True
    color "#00589E" # E60000
    hover_color "#E60000"
    outlines [(3, "#000", 0,0)]

style hover_color_buttons:
    size 35
    hover_color "#d94c3a"

style ds_mod_style:
    bold True
    color "#00589E" # E60000
    hover_color "#c184ff"
    outlines [(3, "#000", 0,0)]

style ds_mod_style_red:
    bold True
    color "#E60000" # E60000
    hover_color "#c184ff"
    outlines [(3, "#000", 0,0)]

image enter_mod_idle = "images/cheat/hacker_cyber_crime-512.png"

image enter_mod_hover = "images/cheat/hacker_cyber_crime-5123.png"

image exit_mod_idle = "images/cheat/hacker_cyber_crime-512.png"

image exit_mod_hover = "images/cheat/hacker_cyber_crime-5123.png"

User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Is that possible to hide/unhide textbutton?

#3 Post by iDweadith »

It worksss! Thank you rayminator

I never knew I could use conditional statements into a screen

User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Is that possible to hide/unhide textbutton?

#4 Post by iDweadith »

Another question

So I did something like

Code: Select all

init 1:
    $ mod_show = False
    $ mod_button_show = True

screen admin_screen:
        if mod_button_show:
            if mod_show == False:
                textbutton "Hello" action SetVariable("mod_show", "True")
            elif mod_show == True:
                textbutton "Hello2" action SetVariable("mod_show", "False")
But this doesn't work well

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

Re: Is that possible to hide/unhide textbutton?

#5 Post by strayerror »

True and False in your SetVariable calls should not be quoted. :)

Additionally you could even simplify this to:

Code: Select all

screen admin_screen:
    default open = False

    if open:
        textbutton "Hello2" action SetScreenVariable('open', False)
    else:
        textbutton "Hello" action SetScreenVariable('open', True)
Which has the advantage of keeping the variable open contained within the screen itself. If this is not wanted (i.e. you want open to be global) then changing SetScreenVariable to SetVariable should have you covered. :D

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Is that possible to hide/unhide textbutton?

#6 Post by rayminator »

this what I have created

Code: Select all

if mod_button_show:
        if mod_show == False:
            textbutton "Hello" action SetVariable("mod_show", True) xalign 0.10 ypos 0.02
        elif mod_show == True:
            textbutton "Hello2" action SetVariable("mod_show", False) xalign 0.10 ypos 0.02

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Is that possible to hide/unhide textbutton?

#7 Post by Imperf3kt »

I'd simplify it further to

Code: Select all

screen testing():
    default var1 = True

    vbox:
        if var1:
            textbutton _("one") action ToggleScreenVariable("var1", False)
        else:
            textbutton _("two") action ToggleScreenVariable("var1", True)
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Is that possible to hide/unhide textbutton?

#8 Post by iDweadith »

Thank you again guys it works perfectly!!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]