SetTimeOut - App Lab

Hi,

I am wondering if it’s possible to change screens without having to do anything. More specifically, I want the screen to switch to the next one without having to do anything. This is for an app with multiple screens, and I only want this function for one of the screens. I tried making a variable for screens, and using the “If” loop, but that didn’t work. Any help would be appreciated!

@aaminahq0609

It is definitely possible to switch screens without an ‘event’. However, how the other screens appear may be ‘interfering’ with that process. If you can give a description of why any of the screens appear, it would help. A share link to what you have already would be great also.

Happy computing,
Andrea

Thanks for the reply!

Here is the link to my app: https://studio.code.org/projects/applab/suAp4 (although the actual app is in Norwegian so I’ll just explain it).

I’m wanting to do this feature on the screen named “Spørsmål5” as well as “Spørsmål9”. For number 5, I’d like to have the screen on for 15 seconds and automatically change to “Spørsmål6” after.

For number 9, there is a little game where you have to click the face as many times as you can in 10 seconds. There is no limit to how many times you have to click. So what I want for this one, is for it to change to screen “Ssiste(Vinner)” after 10 seconds.

I tried making a variable for screen and increasing it by 1 for each screen, so that by the time the variable was worth for example 5, I could just use an “If var screen = 5: setTimeout” but that didn’t work unfortunately. .

1 Like

@aaminahq0609

The link we need has to come from the share button located on the left side of the top menu bar.

I think your explanation may be enough to help cross the language barrier.

Happy computing,
Andrea

I’ll add in my $0.02. Here is a very basic example that shows functionality with a re-usable function to switch to a screen after a given number of seconds.

NOTE: doing stuff with timers is TRICKY. And it’s tricky because there are several ways to do the same thing, and also time itself is a beast.

The biggest thing to understand is that there is NO WAY in javascript to constantly check in on time. You need to set up timers that call functions. Only when functions are called can you check in on the state of things or execute code. setTimeout is one way to do this - a way to set a one-time event to occur in the future.

My example shows a more pure javascript-y way…You need to realize that setTimeout is like setting a timer for something to happen in the future. You don’t need to check in on it (with an if statement for example) it will just happen. This can make it hard to control or synchronize with other timed things (but you can get the hang of it).

Baker
CSP Team

1 Like

@aaminahq0609

Here is a link to something I think I understood from your description. Hopefully, between Baker’s example and mine you can fix yours.

Andrea

1 Like

Hi, I managed to fix the issue. Thank you very much!

Thank you! Several of my girls just used this post to help them!

Tara

1 Like