How can I shorten this code so I use less blocks? (if it's possible)

I apologize if this is not the right place to ask this.


Giving some context if it’s necessary, I have a screen with 4 images of pieces of meat. Each meat has a variable related to it called “meat” followed by a number. When one of the images is clicked, said variable is set to false and the image is made invisible. I wanted to simplify this code with functions, and the variable parts worked fine. I basically made it so the function had an input, and then it checks if that input is true. If it is, image is visible. If it isn’t, image is invisible. And then, in the “when Kitchen Screen Opens” block, I’d set the input to the variable meat0 and then run the function, right under it I’d set the variable to meat1 and do the same. You might have realized the problem, I can’t change the function’s “set “picture’s” visible to false” to make it so “picture” matches the function’s input. Is there a way around this? I find it unnecessary for my code to be this big for something so simple.

Great question!

Yes, you can simplify this code with Any Component blocks. I’m not at my computer so I can’t set up the blocks but the basic idea would be:

When image is clicked, set component’s visible to not component’s visible

I think that would be 4 blocks total. The “component” block is a green block that is part of the Any Component click event block.

1 Like

Oh that is a wonderful block that I didn’t know about, thank you so much.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.