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
stop [other scripts in sprite v]
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:

when I receive [win v]
forever

reset timer
end
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:

when I receive [win v]
forever

reset timer
end
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:

when I receive [win v]
forever

reset timer
end
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
when green flag clicked
repeat until <(win) = [ yes]>
change [time v] by (1)
wait (1) secs
end
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:

when I receive [win v]
forever

reset timer
end
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
when green flag clicked
repeat until <(win) = [ yes]>
change [time v] by (1)
wait (1) secs
end
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.

when I receive [start-timer v]
set [time v] to [0]
repeat until <<(win) = [ yes]> or <(time) > (20)>>
change [time v] by (1)
wait (1) secs
end
if <(time) > (20)> then
// lose script or broadcast
else
//win script or broadcast
end
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:

when I receive [win v]
forever

reset timer
end
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:
when green flag clicked
set [win v] to [0]


when green flag clicked
repeat until <(win) = [1 ]>

change [timer v] by (1)
wait (1) secs
end


when green flag clicked
if <(win) = [1 ]> then
stop [other scripts in sprite v]

say [You win!] for (2) secs
end

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):
when gf clicked
set [timer stopped v] to [0]//Makes the timer go when the project is started.
when gf clicked
forever
if <(timer stopped) = [0]> then
set [timer v] to (timer)
end
end
//Then use
set [timer stopped v] to [1]
//to stop the timer and
set [timer stopped v] to [0]
//to 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):
when gf clicked
set [timer stopped v] to [0]//Makes the timer go when the project is started.
when gf clicked
forever
if <(timer stopped) = [0]> then
set [timer v] to (timer)
end
end
//Then use
set [timer stopped v] to [1]
//to stop the timer and
set [timer stopped v] to [0]
//to continue the timer.



[/quote]
Uh?
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


when I receive [start-timer v]                // just lets you start the timer when you want rather than as a green flag script
set [time v] to [0] // initialise the timer
repeat until <<(win) = [ yes]> or <(time) > (20)>> // either of these conditions stops the loop **
wait (1) secs // wait one second (I've reordered this line and next)
change [time v] by (1) // increase the timer
end
if <(win) = [ yes]> then
// win script or broadcast // if the repeat ended with a winner do one thing
else
//lose script or broadcast // otherwise do something else
end

** 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):
when gf clicked
set [timer stopped v] to [0]//Makes the timer go when the project is started.
when gf clicked
forever
if <(timer stopped) = [0]> then
set [timer v] to (timer)
end
end
//Then use
set [timer stopped v] to [1]
//to stop the timer and
set [timer stopped v] to [0]
//to 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