Larisa
Larisa

Reputation: 791

Casting strings to numbers in App Inventor

The title is perhaps misleading but I don't know how this is called. I do want to know how to type cast for example an int variable to create a string image_number, where number is the value of that variable.

But the thing that bothers me the most is how to call for example an imageSprite with a string constructed in similar way.

I have 16 sprites in a list and some for loops, and have trouble calling sprites. I want to for example check whether that particular sprite has an image set. I know I can use the block that tells me whether that's the case or not, but I want to say:

if the number you are increasing is n, I want you to check whether imageSprite_n has an image set or not (without using if number == n, use imageSprite_n).

I hope my question is clear. Is there any way to do that or should this be done without a loop?

Upvotes: 0

Views: 1876

Answers (1)

Taifun
Taifun

Reputation: 6293

Learn how to work with lists

and learn how to use the advanced blocks

Then you can do it like this

enter image description here

The example uses 4 image sprites and checks, if image sprite 3 has an image set

Upvotes: 1

Related Questions