How to Add a Delay Function


#1

Hi,
I want to add a Delay Before getting Images from firebase. What my App does is - it gets url from Firebase and Post it to Images In the app so I wanted to add a delay In between getting each image. I have Uploaded the Blocks.


#2

u can use clock component forr delay function.


#3

But how? How does the clock Component Adds a delay between getting the images. Please look at my code and find a suitable solution


#4

what about using the logic used here do download files one by one? https://puravidaapps.com/filebyfile.php

Taifun


#5

Where is the Delay Function in it? I have done it in the same way give there already but i am. Looking for a delay function


#6

well, there is no delay inside that example, because it loads the files one by one as fast as possible without delay

to add a delay, use the clock component
Please Wait method by Scott

Taifun


#7

I need to use Variables for Count down. @PixiiBomb would know about it.

I need to add a delay using the Variables only and use the clock Component to reduce the value of the variable


#8

sure… just do it
and if you have issues, post a screenshot of your relevant blocks
Taifun


#9

Heyoooo!
First of all, we gotta clean up those blocks.
Look for patterns in your blocks. If you’re doing the same thing 15 times, but the number changes, that’s a pattern.

Your Event: MAIN_IMAGE_DB.GotValue uses a variable called "to_set_wallpaper"
And you have 20 different conditions that all do the exact same thing based on the value of “to_set_wallpaper”

And you have 20 different versions of the procedure wN (where N is the number)
Instead, since your variables are global, you can just make ONE Procedure called "w"
In your MAIN_IMAGE_DB.GotValue Event, delete EVERY SINGLE condition.
And just add ONE call to the procedure called “w”

Then delete ALL 20 wN procedures.
Instead, you just need 1 procedure. In this procedure, use an Any Component for an Image that sets the Picture to w_value.
You’d want a list called “image_list” with 20 items. One item for each of your pictures (w1-w20. Use their component names, the very last block. Not w1.picture)
This sets a numeric index for each of your images.
w1 is now index 1 in the image_list.
w2 is now index 2 in the image_list, etc
So if “to_set_wallpaper” is 1, than you’d set the component using a “select list item” block.
The list would be “image_list” and the index would be “to_set_wallpaper”

Something like this: (I haven’t tested it, I just threw some blocks together - and obviously your image_list would have 20 items instead of 5)

Each of your individual buttons do need to have their own click event (w1.Click - w20.Click) which is fine because there is no “any component” for a button click event, unfortunately. However, that image that you’re grabbing from firebasestorage.googleapis.com… I would suggest saving that image locally in your app (upload it to the media folder). Call it something like “default.png”. So the valueIfTagNotThere should be “default.png” instead of “firebase.googleapis.com/v0/b/abcdefghijklmnop…”

Ok now about the delay… Where are you wanting to place this delay?
In initial_loading_img_set?

It’s important to understand the workflow before you start adding delays. Because a “delay” procedure has it’s uses, but it’s also really bad programming practice.

Additionally, doing something like:
do this
delay
do this
delay
do this
delay

isn’t going to work. Logically, you might think that it would, but programmatically, it will not.
Which is why you need to establish your work flow, and make your clock react to your workflow.

I do use the clock component a lot in my tutorials, so you might be referring to this little snippet:
simpleclock

Anyway, I know that’s a lot of information to take in. But I think once you clean up your blocks and recognize your patterns, you might find it easier to create a workflow. :slight_smile:


#10

Thanks @PixiiBomb. I got a lot. Of knowledge from your explanation. Thanks for putting the effort into this. Really appreciate it and is greatful to you.

Thank you Very Much!!


#11

The Main Reason I wanted a Delay Was Because The App Crashed When More than 1 Image was Loaded from Firebase