How do I change multiple images depending on the value of my firedatabase?

I have 20 images that represent the status of the egg, and in my firebase database I have a node named eggs with 20 values depending on those values the image will either be egg0,egg1,egg2,egg3. How can I do it a shorter way?
My database looks like this
eggs

  • 1 : 0 # this should make the first egg be egg0.png
  • 2 : 2 # this should make the 2nd egg be egg2.png
  • 3 : 1 # this should make the 3rd egg be egg1.png

I've tried multiple things but I'm just not familiar with MIT, I've tried to put all the images in a list but don't know how to change their images while looping through them.

As for the database I tried to loop and join the tag and the number it works but is there any shorter way?

For setting the image if it should be egg1, egg2, i tried to do it via putting the values in a list but I think it's not possible to set an image value to the text of it's path and I have to select it manually. Any ideas? Thank you!

Hello and welcome,

you can make a list with the images and then, depending on the value received from firebase, select the corresponding element from the list:
image

Keep in mind that in AI2 the lists start with index 1, so if your first value in Firebase is 0, you must add +1 to the value to use it as an index.

Hey thank you! Can you spoon feed me for a little bit on how the blocks are supposed to look? I dont know how to set the image in this block thanks!!

It would be something like this. You have a list with the images and you use the value received (+1) like index to select the image from the list:

1 Like

You may run into problems if your nodes are number from 1 upwards, Firebase will try to treat this as an array. Suggest use strings for your nodes, e.g. A,B,C... instead of 1,2,3...

1 Like

You're right just found this was the reason my label is printing wrong values, thanks for the heads up!!

Thank you very much for your help!! This works thank you again!!