Page 1 of 1

Disabling button/screens

Posted: Fri Apr 16, 2021 9:19 am
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!!

Re: Disabling button/screens

Posted: Fri Apr 16, 2021 10:05 am
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)

Re: Disabling button/screens

Posted: Fri Apr 16, 2021 3:46 pm
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:

Re: Disabling button/screens

Posted: Fri Apr 16, 2021 4:09 pm
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")]

Re: Disabling button/screens

Posted: Tue Apr 20, 2021 9:47 am
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