How to change visibility of an image (whose name has index) dynamically?

amvukovic shared this question 2 years ago
Answered

I have several images with names 'slika1' to 'slika6' and a numeric variable 'redBr' which refers to images' indexes in names and changes dynamically...

In particular moment I would like to be able to hide

"slika"+redBr

so I've tried SetVisibleInView() command combined with Object() command and I've also tried to put images into a list - as objects

slike={slika1,slika2,slika3,slika4,slika5,slika6}
and then
SetVisibleInView(Element(slike,redBr),1,false)


but none of these works...

It looks like you can only directly refer to an image as

SetVisibleInView(slika1,1,false)
but in my code this index slika1 etc. is stored in a numeric var 'redBr' so I don't know how to call the name of the image (including var 'redBr') within GGB scripting...

I'm trying to create the whole game in GGB scripting only...

Thanks in advance

Comments (5)

photo
1

you can add redBr==1 in properties->advanced->condition to show object of silka1

redBr==2 in properties->advanced->condition to show object of silka2

etc

photo
1

Dear mathmagic!

Thank you for your quick reply but my explanation wasn't detailed enough...

I'm creating a game in which space ships with task solutions are falling down and you have to shoot the right solution (space ship) with a projectile according to the given task...

So, if you shoot the right one then the image of a space ship together with the solution text are supposed to "disappear"...

So, that's why I can't (or doesn't see how to... in this moment) change properties the way you have suggested because the var 'redBr' is, in fact, the number of the "shot" space ship... So, if you shoot the right one, then the image 'slika'+redBr and text 'rjesenje'+redBr should become invisible... if you're wrong all the ships will "fall" down a little bit...

The biggest problem is that every time you "drive" a gun through "the scene" the var redBr changes accordingly (gets the value - number - of the boat (image) under which its at the moment)... Later on (after shooting) I'm checking whether the right space boat is shot or not...

Once again thank you very very much... I have an idea according to your suggestion (it's not 100% clear to me at the moment) but I was hoping to avoid so many different variables...

Best regards

Alex

photo
photo
1

The only thing that I've found that works is this:

Execute[Sequence["SetVisibleInView[slika"+k+",1, false]", k, redBr, redBr]]

Once again thank you very much!

photo
1

random show of three triangles

see properties of t1,t2,t3

Files: foro.ggb
photo
1

Thanks again!

I've used Execute() command with commands stored in text variables...


Here's the game I've created... If you have any suggestions you're most welcome!

Game Space Invasion

Best regards

photo
© 2019 International GeoGebra Institute