Need help with "if something is hidden then...." code THIS IS NOT FOR PT

This is a small part of a larger project. How can I write an if statement that says if an image is hidden. then make something happen (like play a sound). I have looked up a few things and cannot get it to work. I added a variable x in just to watch the value. Any help would be appreciated. Here is a link to see the project. Thanks in advance for any help.

Since this is the time when students are working on the Create PT, I cannot offer specific in-depth debugging help. A hint I can give is that visibility of all UI elements can be controlled by the hidden property.

Piggybacking on Sangeeta’s hint…

Images have a property named “hidden” that will return true or false.

But before that, you need to decide when you’re going to check if the image is hidden. Is there a particular trigger? Should it check when someone presses a button? If so, your code might look something like…

In the event that button x is clicked
   If image1's "hidden" property is true
      Play sound

Remember you can access an element’s properties using the getProperty block (and specify which element and what property as the parameters).

I really like the way you are thinking here. It shows a natural progression into object oriented concepts. Unfortunately, App Lab doesn’t work that way. @infinitestasis looked into adding that with a library. It takes hundreds of lines of code. Abandon that line of thinking.

Instead Frank and Sangeeta are leading you to the simple solution. You have written this code:

setProperty("image1", "hidden", true);
setProperty("image2", "hidden", true);
setProperty("image3", "hidden", true);

and it works. The question everyone wants you to think about is this. What is the opposite of setProperty()?

I am new at teaching this and javascript overall. I included the link to my project. You can see what I have tried. Not sure what the opposite of setproperty is.

Here is a link


The opposite of setProperty() is getProperty(). Hover your mouse over the getProperty() block and then choose See Examples.

Ironically, it will explain how to use it but without examples.

This function returns a value by looking at the current state of HTML elements created on the Design tab. Look through the list of properties and see if there is one of interest to you.

Thanks. The one line of code I need is how to say “if property is hidden then” I tried “if label1.hidden=true then” Just don’t know how to code it.

Thanks. The one line of code I need is how to say “if property is hidden then” I tried “if label1.hidden=true then” Just don’t know how to code it.

Looks like you’ve got the right idea and now it’s mostly syntax, which the blocks might help with.

Let’s say I have a button named button4 and I want to get its height. I could do it like this…

So instead of this, you would need the name of your image and instead of the “height” property, you’re getting the value of its “hidden” property.

1 Like

Thanks. How can I expand that to say if the above is true then play a sound. Thats the part I cannot get to work. I tried this but it didnt work…

if (getProperty(“image1”, “hidden” == true )) {
playSound(“sound://default.mp3”, false);

You can just do this:
if (getProperty(“image1”, “hidden”)){
playSound(“sound://default.mp3”, false);

Thanks, I though on the “if” statement, after “hidden” I thought we would need “=true” or =“false”

I was trying to add too much code.