Help with Simon

I’m currently working on my Simon game. I’m having issues with the function playing back the computer sequence and I think my setInterval function is having issues. Any suggestions would be appreciated.

1 Like

Read the article Ed shared…I used the same strategy, having found some advice from a different place.

Basically instead of thinking of the playing of the tones as creating 1 tone at a time with a delay, you want to pre-arrange all 20 tones (or whatever step you’re on) from the start by having tone 1 play at 1 second, tone 2 at 2 seconds, tone 3 at 3 seconds…instead of tone 1 at 1 second, tone 2 1 second later, tone 3 1 second later.

it’s tricky b/c it seems like those should be identical but it’s really challenging to overcome understanding about asynchronous JS functions. Using an interval inside a loop sets up all the intervals at once, so you play 3 tones simultaneously with 1 second delay, instead of 3 tones 1 second apart.

Hope that makes sense

I think that makes sense. It loads all the sounds in the sequence then plays them 1 second apart instead loading 1 at a time. Did I understand that correctly?

Thanks Ed, I actually got this link from other Simon threads. I’m pretty sure you were in that thread also. It’s cool you guys are active on this forum, thanks in advance for putting up with my “writer’s block”.