Advice : How to handle insensitive button with my code

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
sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Advice : How to handle insensitive button with my code

#1 Post by sculpteur »

Hi again,
Thanks to Remix i mangage to get a first working result for my inventory system.


But now I am trying really hard to find a way to handle the fonction to make a button sensitive or insensitive.
Iam not talking about hovering. The hovered button works fine. But sometime I want it to be disabeled (but not hidden) in order to use the insensitive image button (the button will be gray).



So please if someone could take a look at this and tell me :
1 - What is the syntax for using the insensitive button fonction,
2 - What's the best way to impement it in this code.
3 - The best for me will be to find a way to order my button to become sensitive/insensitive from my story progression label (in script folder, not screen folder).

Exemple :
label dialog_with_jessica:
e "blabla"
j "Did you have an apple on you ?"
---> here : make button inventory sensitive.

PS : I know this is a really specific request but I am just hoping their is a person aroud here who has some experience with this insensitive shit. So thank you in advance!


ILLUSTRATION OF THE CODE :

The following images are the result of my code right now. Its just to illustrate what we are talking about.

Image 1 : here you can see the story in progress, and a little inventory button on the right of the say window.
Image
Image 2 : here you can see the story in progress, and the hovered image of my little inventory button when the player pass the mouse on it.
Image
Image 3 : here you can see the story stop temporarily and display the inventory bar when the players click the inventory button.
Image
Image 4 : this is what happens when the player hit again the inventory button on the right. This come back to the story progression.
Image


THE CODE :

Code: Select all

image 0-0-inv_bar_simple = "gui/Inventory_bar_simple.png"
image 0-0-inv-butt-small = "gui/inventory_button.png"
image 0-0-inv-butt-small-hover = "gui/inventory_button_hover.png"
image 0-0-inv-butt-small-insensitive = "gui/inventory_button_insensitive.png"


screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if show_inventory:
            pass

        else:
            text what id "what"
            if who is not None:
                window:
                    style "namebox"
                    text who id "who"
    imagebutton:
        keysym "i"
        xpos 0.806 ypos 0.859
        insensitive "0-0-inv-butt-small-insensitive"
        idle "0-0-inv-butt-small"
        hover "0-0-inv-butt-small-hover"
        action [ToggleVariable( "show_inventory" ), Show("inventory_main")]




screen inventory_main:
    modal True
    add "gui/Inventory_bar_simple.png" xpos 0.0015 ypos 0.75
    #Here i will add all the inventory fonctionnality (displaying item in the slot, etc)
    imagebutton:
        keysym "i"
        xpos 0.806 ypos 0.859
        insensitive "0-0-inv-butt-small-insensitive"
        idle "0-0-inv-butt-small"
        hover "0-0-inv-butt-small-hover"
        action [ToggleVariable( "show_inventory" ), Hide("inventory_main")]
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Advice : How to handle insensitive button with my code

#2 Post by Remix »

action [ ... various actions ... , SensitiveIf( len( inventory ) ) ]

or

default inv_button_sensitive = False # outside of label/screen etc
imagebutton:
....sensitive inv_button_sensitive # might work - obviously without the dots... hmmm, typing [code] would have been quicker, d'oh
Frameworks & Scriptlets:

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Advice : How to handle insensitive button with my code

#3 Post by sculpteur »

In fact i was more trying to give my button a variable to be able to change his state from a label in the script file.
Because otherwise it will make me creat a second distinct button...

That mean I dont want the sensitive/insensitive state change after/following an "action" from a screen,
I want it to change after a command that I can write in a label from the script file.

And iam guessing this fonction exist for a reason but iam still wondering how to do it as simple as the hovering fonction works.
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Advice : How to handle insensitive button with my code

#4 Post by sculpteur »

Is someone have any idea of what iam talking about ? Or maybe i just didnt understood the way "the insensitive state" is suppose to work.
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Advice : How to handle insensitive button with my code

#5 Post by Remix »

Surely the SensitiveIf action I linked does that, just pass it a boolean variable and toggle the variable value within the script...

Code: Select all

default inv_button_sensitive = False # outside of label/screen etc

# in the button in the screen
action [ ... various actions ... , SensitiveIf( inv_button_sensitive ) ]

# script
label a:
    "..."
    $ inv_button_sensitive = True
    "..."
Frameworks & Scriptlets:

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Advice : How to handle insensitive button with my code

#6 Post by sculpteur »

Oh really nice, sorry i didn't understood it that way the first time. Thank you !
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

Post Reply

Who is online

Users browsing this forum: Google [Bot]