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

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
jepp21
Regular
Posts: 74
Joined: Fri Feb 10, 2023 3:46 pm
Contact:

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

#1 Post 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
Last edited by jepp21 on Wed Mar 13, 2024 11:14 pm, edited 1 time in total.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

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

#2 Post 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]

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

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

#3 Post 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)

jepp21
Regular
Posts: 74
Joined: Fri Feb 10, 2023 3:46 pm
Contact:

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

#4 Post 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!

Post Reply

Who is online

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