Disabling button/screens

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
Naisha
Newbie
Posts: 5
Joined: Fri Apr 16, 2021 9:08 am
Contact:

Disabling button/screens

#1 Post by Naisha »

Hi! This could be a pretty newbie question but in my game I have several screens with several buttons that, once they are clicked, they jump to different labels. The problem is that, when once of this button is clicked, if another one is clicked it interrupts the tasks of the previous button (obviously). So I would need a way to disable the buttons once I clicked in one of them. I don't want to hide them, but be inactive/insensitive.

I tried with something like this, but also stops the tasks of the previous button.

Code: Select all

imagebutton:
        xpos 202 ypos 750
        idle "cauldron.png" hover "cauldronbright.png"
        if allowInteraction == 1:
            action Jump ("cauldronSelected")
        else:
            action Null
I'm pretty sure there should be a way, but I'm not able to find it. Thanks in advance!!

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Disabling button/screens

#2 Post by RicharDann »

Try using the sensitive property of button:

Code: Select all

imagebutton:
        xpos 202 ypos 750
        idle "cauldron.png" hover "cauldronbright.png"
        sensitive allowInteraction == 1
        action Jump("cauldronSelected")
Or If() screen action:

Code: Select all

imagebutton:
        xpos 202 ypos 750
        idle "cauldron.png" hover "cauldronbright.png"
        action If(allowInteraction == 1, true=Jump("cauldronSelected"), false=None)
The most important step is always the next one.

Naisha
Newbie
Posts: 5
Joined: Fri Apr 16, 2021 9:08 am
Contact:

Re: Disabling button/screens

#3 Post by Naisha »

Thanks for the reply!
Sadly, I'm not able to make it work. At first, the sensitive command seems to do it well because the game starts with allowInteraction =0 and no button is working, but thenwhen my var allowInteraction is 1 (I checked on the console it really was 1) the buttons were not working (just in case, when allowInteraction is 0 no button should work, when allowInteraction is 1, all buttons should work).
I also tried the second option with

Code: Select all

 action If(allowInteraction == 1, true=Jump("cauldronSelected"), false=None)
but it seems the action None still interrupts what's going on in the game.

I also tried a bit tricky option. I added an invisible screen over all the game just to try to cover the rest of the buttons with that screen, but it seems ren'py execute all the screens as if they were on the same layer, so if you click on a place with several buttons there, ren'py will execute all the actions of all those buttons.

Any ideas? :cry:

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

Re: Disabling button/screens

#4 Post by rayminator »

question

are those buttons shown through the game or not?

if not then you want use Hide like this

Code: Select all

screen test:
     blah
     vbox:
          imagebutton:
               xpos 202 ypos 750
               idle "cauldron.png" hover "cauldronbright.png"
               sensitive allowInteraction == 1
               action [Hide("test"), Jump("cauldronSelected")]

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Disabling button/screens

#5 Post by RicharDann »

Naisha wrote: Fri Apr 16, 2021 3:46 pm Sadly, I'm not able to make it work.
Sensitive seems to be working for me. How did you declare allowInteraction variable? You should declare it with default statement and outside of a label.

You can also try SensitiveIf().

Here's the code I used to test.

Code: Select all

default allowInteraction = 0

screen test:
    frame:
        has vbox
        textbutton "Label 1": 
            sensitive allowInteraction == 1
            action Jump("label_test")

label start:
    
    show screen test    

    "None of the buttons work"
    
    $ allowInteraction = 1 # Enable buttons
    
    "Buttons are working now"
    
    return
    
label label_test:    
    
    $ allowInteraction = 0 # Disable buttons
    
    "Label test is running and buttons are disabled"
    
    return
The most important step is always the next one.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]