Discuss Scratch

kingdanny54
Scratcher
9 posts

How to stop the timer when you win?

In my game, https://scratch.mit.edu/projects/73906534/ , I made it so that when you win,you go to the win page, the timer is supposed to stop. I tried to broadcast to the sprite with the timer to stop by tirning on the stop script, but that does not work. Can someone help me?
deck26
Scratcher
1000+ posts

How to stop the timer when you win?

You still have a repeat 20 loop telling the variable to show and changing its value. You need to tell that script to stop - perhaps with
stopother scripts in sprite
Zekrom01
Scratcher
1000+ posts

How to stop the timer when you win?

Unfortunately, I don't think it's possible to stop the timer with just one block. However, you should consider trying this:

whenIreceivewinforeverresettimer
This will “reset” the timer so it's always at 0. However, there is no possible way to hide the timer itself, though.
kingdanny54
Scratcher
9 posts

How to stop the timer when you win?

Actually Zekrom, It wasn't a timer. It is a variable.

Last edited by kingdanny54 (Aug. 24, 2015 17:09:50)

deck26
Scratcher
1000+ posts

How to stop the timer when you win?

Zekrom01 wrote:

Unfortunately, I don't think it's possible to stop the timer with just one block. However, you should consider trying this:

whenIreceivewinforeverresettimer
This will “reset” the timer so it's always at 0. However, there is no possible way to hide the timer itself, though.
I don't think they're using the built-in timer; they're using their own coded timer.
kingdanny54
Scratcher
9 posts

How to stop the timer when you win?

But i'm using a variable as a timer. How do I stop that?
Zekrom01
Scratcher
1000+ posts

How to stop the timer when you win?

deck26 wrote:

Zekrom01 wrote:

Unfortunately, I don't think it's possible to stop the timer with just one block. However, you should consider trying this:

whenIreceivewinforeverresettimer
This will “reset” the timer so it's always at 0. However, there is no possible way to hide the timer itself, though.
I don't think they're using the built-in timer; they're using their own coded timer.
What do you mean? like they used a sprite for it?
koda1956
Scratcher
100+ posts

How to stop the timer when you win?

kingdanny54 wrote:

But i'm using a variable as a timer. How do I stop that?
just use something like this
whenclickedrepeatuntilwin= yeschangetimeby1wait1secs
deck26
Scratcher
1000+ posts

How to stop the timer when you win?

Zekrom01 wrote:

deck26 wrote:

Zekrom01 wrote:

Unfortunately, I don't think it's possible to stop the timer with just one block. However, you should consider trying this:

whenIreceivewinforeverresettimer
This will “reset” the timer so it's always at 0. However, there is no possible way to hide the timer itself, though.
I don't think they're using the built-in timer; they're using their own coded timer.
What do you mean? like they used a sprite for it?
No, a variable, changing by 1 every second in a loop.
kingdanny54
Scratcher
9 posts

How to stop the timer when you win?

I'm so confused…
]
koda1956
Scratcher
100+ posts

How to stop the timer when you win?

koda1956 wrote:

kingdanny54 wrote:

But i'm using a variable as a timer. How do I stop that?
just use something like this
whenclickedrepeatuntilwin= yeschangetimeby1wait1secs
when you win, set win to yes. when the variable win is at yes, it stops the timer variable.
deck26
Scratcher
1000+ posts

How to stop the timer when you win?

kingdanny54 wrote:

I'm so confused…
]
Why?

@koda1956's suggestion is OK but you might not want the timer to start immediately with the green flag - perhaps a broadcast when you're ready to start the timer. I suspect you also want the timer to decide when the game is lost.

whenIreceivestart-timersettimeto0repeatuntilwin= yesortime>20changetimeby1wait1secsiftime>20thenelse lose script or broadcast
Zekrom01
Scratcher
1000+ posts

How to stop the timer when you win?

deck26 wrote:

Zekrom01 wrote:

deck26 wrote:

Zekrom01 wrote:

Unfortunately, I don't think it's possible to stop the timer with just one block. However, you should consider trying this:

whenIreceivewinforeverresettimer
This will “reset” the timer so it's always at 0. However, there is no possible way to hide the timer itself, though.
I don't think they're using the built-in timer; they're using their own coded timer.
What do you mean? like they used a sprite for it?
No, a variable, changing by 1 every second in a loop.
Oh. Ok.

In that case, make a variable called win. In the beginning, set it to zero, then if you win, set it to 1.

Like this:
whenclickedsetwinto0whenclickedrepeatuntilwin=1 changetimerby1wait1secswhenclickedifwin=1 thenstopother scripts in spritesayYou win!for2secs

I hope this works…

Last edited by Zekrom01 (Aug. 24, 2015 17:32:19)

monstermash3
Scratcher
1000+ posts

How to stop the timer when you win?

It is impossible to stop the actual timer. With two variables (the “timer” being the timer):
whenclickedsettimer stoppedto0Makes the timer go when the project is started.whenclickedforeveriftimerstopped=0thensettimertotimersettimer stoppedto1to stop the timer andsettimer stoppedto0to continue the timer.
kingdanny54
Scratcher
9 posts

How to stop the timer when you win?

monstermash3 wrote:

It is impossible to stop the actual timer. With two variables (the “timer” being the timer):
whenclickedsettimer stoppedto0Makes the timer go when the project is started.whenclickedforeveriftimerstopped=0thensettimertotimersettimer stoppedto1to stop the timer andsettimer stoppedto0to continue the timer./quoteUh?
kingdanny54
Scratcher
9 posts

How to stop the timer when you win?

/so confused
deck26
Scratcher
1000+ posts

How to stop the timer when you win?

kingdanny54 wrote:

/so confused
Let's see if I can help.

I suspect you're seeing the different solutions and that's not helping. There's always multiple ways of coding things and I'm not going to compare the different solutions but obviously I prefer to talk about my own offering.

So the key is the timer will continue until you tell it to stop and what you had was the condition where you'd detected a winner but the timer was still running. So somehow, when the winner is detected the timer needs to stop.

There is a built-in timer (the blue timer block) which is more accurate than using your own code but it's probably overkill and causing confusion in your case. So let's ignore that.

So my solution as shown earlier


whenIreceivestart-timer just lets you start the timer when you want rather than as a green flag scriptsettimeto0 initialise the timerrepeatuntilwin= yesortime>20wait1secs wait one second (I've reordered this line and next)changetimeby1 increase the timer either of these conditions stops the loop **ifwin= yesthenelse win script or broadcast // if the repeat ended with a winner do one thing

** you may prefer to use time = 20 in the repeat until conditions

Any questions?

kingdanny54
Scratcher
9 posts

How to stop the timer when you win?

Got it. thanks.
coke11
Scratcher
1000+ posts

How to stop the timer when you win?

Check THIS out.
monstermash3
Scratcher
1000+ posts

How to stop the timer when you win?

kingdanny54 wrote:

monstermash3 wrote:

It is impossible to stop the actual timer. With two variables (the “timer” being the timer):
whenclickedsettimer stoppedto0Makes the timer go when the project is started.whenclickedforeveriftimerstopped=0thensettimertotimersettimer stoppedto1to stop the timer andsettimer stoppedto0to continue the timer.
Uh?
(sorry I forgot to close my tag, closing it now)

See my project Drawing Project 1.6 for an example.


Powered by DjangoBB