Changing the opacity of text mid-routine

So I’m trying to make a clickable “help” button that reveals some text. Originally the opacity variable for the text is set to 0, and set to update every frame. The following code is used in the “begin routine” tab to set the opacity of the help text to 0 in every repeat.

opacity1 = 0

In the “each frame” tab the following code is used to detect a click on the help icon, changing the opacity of the text, revealing it.

if mouse.isPressedIn(help_icon) and clicked == 0:
    print("button was pressed")
    
    opacity1 = 1
    clicked = 1

The “clicked” variable is there to ensure the button can only be pressed once per repeat of the routine and is set to 0 in the “begin routine” tab as well. The “print” function is there for debugging purposes to check if the code detects that the button was pressed. It always executes when I run the code and click the button, confirming that it detects the click.

My problem is that the help text is always revealed, it is never hidden. From when the routine begins, regardless of whether the help icon was pressed or not, it is always visible. How can I fix this?

Hi @LelBartha, if you set the opacity to zero but update this on each frame, the text is created using the default text opacity of 1. The problem here is that you cannot dynamically alter the text components opacity, so you are stuck with the default in this scenario. An alternative way to do this will be to layer an extra shape over the text, and change the opacity of that layer to zero when the button is clicked. This will give the same effect of revealing the hidden text.

It works perfectly! Thank you for the help!!