Cloning images returns blanks

Hi All!
I have a problem and have had no luck searching for the answer.

In my app I am simply cloning an image 29 times.
Each clone gets an image randomly from a list of 6 images.
For some reason I end up with blank clones. Each time I load the screen the blanks are in different positions. The number of blank clones also varies.
I have tried using a list, a Local DB and local storage data source and the result is the same.
I thought maybe the blank is from the blank row that you get at the bottom of your DB. So I tried limiting the random images to two from the list, but the blanks still appear.

I hope I am missing something simple. Any guidance is really appreciated.
Screenshots below.

Thank you. Inga


Hi Inga,

What’s happening is that your repeat loop is firing the Clone block repeatedly without any delay. But the “do” section of the Clone block doesn’t have time to complete it’s blocks before the next image clone is created.

So you either need to add a Wait block inside the repeat loop, after the Clone block, and set it to a small number like 0.01 or 0.03. That may work.

Or, you need to do all the cloning first and then use a separate loop to set the pictures of all of the cloned images. That would be my approach.

2 Likes

Yes! Thank you that worked. I put a wait of 0.1 seconds after the clone and before setting the random image.

Thanks again Tatiang!

Beware, using a fixed wait time like that can cause erratic behavior across devices.

Two alternatives to consider are the data list viewer JSON Bound Data List Viewer - No More Cloning! and waiting until the operation is finished Wrapping Asynchronous (then do) blocks into a Synchronous Function resolves unpredictable results.

These examples are for slightly different circumstances, but hopefully you get the idea.

Happy Thunking

3 Likes

Agreed, I’m not a fan of wait blocks but sometimes it’s a simpler way to quickly test if something will work.

Thank you. I’ll do some testing and see how I go. Good to know there are options.