[SOLVED] Problem with length of list block

Hello,

I have a for loop, inside of which I have a long if statement. Within that if statement, I have this block:
image

Right after that if statement (but still within the for loop) I am showing the length of the same list (IDsAlreadyDisplayed) in an Alert. However, it is giving the result as 0, even though the list has 3 items at the same time (I checked this using a ListView)

If I move the Alert.show block to right under the insert in list block, It works perfectly.

Why are the blocks not going in the correct order for the for loop?

Full screenshot: (I have collapsed the if statement as nothing is of relevance, except the above mentioned insert in list block)

image

Output of Alert (tested on web version):

image

Proof that the list has more than 1 item:

(this is a ListView)

Thanks.

1 Like

Is the IDsAlreadyDisplayed.
Initialized with a create list block?

Yes, I initialized it with an empty list block.

May we see some more screenshots or a link then?

You need to show the full statement. You assumed there is no issues with the part you collapsed which means you want us to fucus on what you are focusing on and therefore no one will get a result.

Allow others to see and evaluate the situation you are facing instead of steering them on a specific part that you decided upon.

Meanwhile, insert a wait block before the notifier1 message and if this does not work then move the wait block after the notifier1 message

1 Like

Here:

image

Ok, will try

1 Like

There’s the insert at last block

yeah i already saw it

Never mind, I managed to solve it using the wait block :slight_smile:

1 Like

The burble Get block for the database is asynchronous which means it will not half the app until the operation is completed but will take the requested operation and allow the app to continue processing next block.

This means your alert block will execute before the realtime_DB Get is completed and therefore you might not see any values in the alert message.

If you insert a wait block before getting the length of the list you will give time to the Get block to execute and provide you with results.

Hope it is clear now.

2 Likes