Adding a Delay?

csd-unit-6

#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


#5

Glad I found this forum, I was able to make a project with this help! Thought I should share incase the example code can help anyone else.


#6

That’s amazing! I just played it in the Seattle office, and everyone loved it. :slight_smile:

Elizabeth


#7

:grinning: Happy you guys enjoyed it. We did not have quite enough time to finish unit 6 this semester, so we are going to end with this project.