Page 1 of 1

[SOLVED] How to make drags disappear after clicking a button?

Posted: Tue Mar 12, 2024 11:20 pm
by jepp21
Hi all, I'm currently working on an in-game computer where each "app" is its own screen within. I have them set up as drags like so:

Code: Select all

screen desktop():

    .....

    ######## Desktop Icons ##########
    ....
    # Chatrooms
    imagebutton: 
        at transform:
            pos (330, 150)
        auto 'images/desktop browse/home/chatroom_icon_%s.webp' focus_mask True 
        action ToggleVariable("chatrooms_open", "True")  
        
    # Area to put all draggable windows in
    fixed: 
        pos(190, 75)
        xysize(1500, 750)

        # Put all screens in this one group
        draggroup:        

            ...

            if chatrooms_open:
                drag:
                    draggable True
                    drag_raise True  
                    use chatrooms
             ...
Each drag uses a screen with a window and its own functionality. There's also a close button:

Code: Select all

screen chatrooms():
    ....
        textbutton "close": 
            action [SetVariable("chatrooms_open", "False")] # I also tried hiding the screen but that didn't work either
            xalign 1.2 yalign -0.2
This set up works for the most part and I'm able to open the screens without any problems. The issue is that closing them doesn't work. When I click on the close button, all the button text just turns white for some reason and the screen stays. I can still interact with the screen normally. The reason I have it set up like this instead of purely putting unique drags within the screens instead is that I wanted certain behaviors like drag_raise, thus requiring them all to be within the same drag group. If anyone has a better idea in mind, I'm all ears but that's what I have for now.

Image

Re: How to make drags disappear after clicking a button?

Posted: Wed Mar 13, 2024 4:52 am
by jeffster
The first thing to try in such cases is adding renpy.restart_interaction
https://renpy.org/doc/html/other.html#r ... nteraction

Code: Select all

        textbutton "close": 
            action [SetVariable("chatrooms_open", "False"), renpy.restart_interaction]

Re: How to make drags disappear after clicking a button?

Posted: Wed Mar 13, 2024 7:54 am
by m_from_space
jepp21 wrote: Tue Mar 12, 2024 11:20 pm

Code: Select all

        action ToggleVariable("chatrooms_open", "True")  
        
        action [SetVariable("chatrooms_open", "False")]
No wonder it doesn't work. You are setting your variable "chatrooms_open" to a string that reads "True" / "False". What you wanted is either toggling it or setting it to True (not a string!). Since a non-empty string is always considered True, meaning "False" is also considered True, the hiding doesn't work.

Code: Select all

action ToggleVariable("chatrooms_open")

# or

action SetVariable("chatrooms_open", True)
# and
action SetVariable("chatrooms_open", False)

Re: How to make drags disappear after clicking a button?

Posted: Wed Mar 13, 2024 11:13 pm
by jepp21
m_from_space wrote: Wed Mar 13, 2024 7:54 am
jepp21 wrote: Tue Mar 12, 2024 11:20 pm

Code: Select all

        action ToggleVariable("chatrooms_open", "True")  
        
        action [SetVariable("chatrooms_open", "False")]
No wonder it doesn't work. You are setting your variable "chatrooms_open" to a string that reads "True" / "False". What you wanted is either toggling it or setting it to True (not a string!). Since a non-empty string is always considered True, meaning "False" is also considered True, the hiding doesn't work.

Code: Select all

action ToggleVariable("chatrooms_open")

# or

action SetVariable("chatrooms_open", True)
# and
action SetVariable("chatrooms_open", False)
Whoops. Not sure how I missed that. Thanks!