Adding a Delay?


#1

I have a program that plays notes and flashes the LEDs. But even though there is a duration to the notes, they all play (and the lights flash) instantaneously. I can’t seem to find any sort of delay or wait. Any help would be appreciated.


#2

Hi Eric,

It sounds like you might want to use the “setTimeout” block in the “Control” drawer. It lets you delay code for a certain number of milliseconds.

https://docs.code.org/gamelab/setTimeout/

Elizabeth


#3

That helped somewhat. It also made me rethink my program.

It seemed like I had to keep increasing the millisecond delay as it went along, instead of being able to put the same amount of delay for each block. I guess I’ll have to experiment with it some more.

Thanks for your help.


#4

Hi Eric,

Yes, it’s not exactly a delay in that it pauses the program for a particular amount of time. It schedules the code to run after a certain number of milliseconds, but the rest of the code continues to run after it gets scheduled. You will have to schedule things for different lengths of timeout if you don’t want them to happen at the same time.

Elizabeth