This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-10-23 23:05:51

nytram
Scratcher
Registered: 2008-10-23
Posts: 8

Timer help

My version of Pong,
http://scratch.mit.edu/projects/nytram/299721

How do I make the timer stop counting when the head hits the red bar at the bottom of the screen?

Offline

 

#2 2008-10-23 23:14:09

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Timer help

Put a <stop all>[/blocks] script in the <if><touching color[ red[/blocks] block.

Last edited by hmnwilson (2008-10-23 23:14:40)


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#3 2008-10-23 23:15:57

natalie
Scratch Team
Registered: 2007-03-07
Posts: 100+

Re: Timer help

The stopall is a good idea -- if you don't mind the program stopping at that point.

As you've found, you can't stop the timer when a program is running.

You could have another sprite appear on top of it -- for example, a sprite that says "Game Over."

OR, If you want the timer value to stay on the screen, you could also create a variable. "hide variable" when green flag clicked, then when the head hits the red bar, "set variable" to the timer value, and then" show variable" (so it covers the running timer). Yeah, probably unduly complicated (and requires Scratch 1.3)

Offline

 

#4 2008-10-23 23:43:17

nytram
Scratcher
Registered: 2008-10-23
Posts: 8

Re: Timer help

Thanks folks. I'll give your suggestions a try.
smile

Offline

 

#5 2008-10-24 04:52:17

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Timer help

I usually just build my own timer using a variable that I update every second in a loop.  The loop tests on a flag variable to see if it should continue looping.  That way it can be turned on or off by changing the value of the flag variable.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2008-10-25 01:33:16

nytram
Scratcher
Registered: 2008-10-23
Posts: 8

Re: Timer help

natalie wrote:

You could have another sprite appear on top of it -- for example, a sprite that says "Game Over."

Okay, I decided to go with this since it seems the simplest solution. Just one question, I made the 'Game Over' sprite, positioned it over the timer and I'm using 

<when green flag clicked>
and
<hide>

blocks to keep the timer visable while the game is in play. How do I cue the 'Game Over' sprite to appear over the timer when the head contacts the red bar?

Offline

 

#7 2008-10-25 06:30:36

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Timer help

nytram wrote:

natalie wrote:

You could have another sprite appear on top of it -- for example, a sprite that says "Game Over."

Okay, I decided to go with this since it seems the simplest solution. Just one question, I made the 'Game Over' sprite, positioned it over the timer and I'm using 

<when green flag clicked>
and
<hide>

blocks to keep the timer visable while the game is in play. How do I cue the 'Game Over' sprite to appear over the timer when the head contacts the red bar?

On the head sprite, set up a script like this:

[blocks]
<when green flag clicked>
<wait until><touching color[ red
<broadcast[ Show Game Over
[/blocks]

And on the Game Over sprite set up a script like this:

[blocks]
<when I receive[ Show Game Over
<show>
[/blocks]

That should do it!

Note that the message "Show Game Over" is something you make up...you can actually use any text you like.  When you look at the Broadcast block, you will see "New" as the only option at first, you pick that then type in whatever you want the message to be.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#8 2008-10-25 12:24:06

nytram
Scratcher
Registered: 2008-10-23
Posts: 8

Re: Timer help

Paddle2See wrote:

On the head sprite, set up a script like this:

[blocks]
<when green flag clicked>
<wait until><touching color[ red
<broadcast[ Show Game Over
[/blocks]

And on the Game Over sprite set up a script like this:

[blocks]
<when I receive[ Show Game Over
<show>
[/blocks]

That should do it!

Note that the message "Show Game Over" is something you make up...you can actually use any text you like.  When you look at the Broadcast block, you will see "New" as the only option at first, you pick that then type in whatever you want the message to be.

Didn't work.
hmm

Offline

 

#9 2008-10-25 13:41:31

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Timer help

Can you share it so I can see why it isn't working?


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#10 2008-10-25 13:49:19

legolover
Scratcher
Registered: 2008-03-11
Posts: 23

Re: Timer help

First, don't worry about a timer. Define a variable "time". When you want the timer to start, use a broadcast "BeginTimer".
[blocks]<when I receive[ start timer
<set{ time }to( 0
<repeat until><touching color[ red
<wait( .01 secsc>
<change{ time }by( .01
<end>
<stop script>[/blocks]

Last edited by legolover (2008-10-25 13:53:06)


Escape the Room 1! http://scratch.mit.edu/projects/legolover/291256

Offline

 

#11 2008-10-25 15:37:26

nytram
Scratcher
Registered: 2008-10-23
Posts: 8

Re: Timer help

Paddle2See wrote:

Can you share it so I can see why it isn't working?

Yes. Thank you.
smile


http://scratch.mit.edu/projects/nytram/302013

Offline

 

#12 2008-10-25 15:38:41

nytram
Scratcher
Registered: 2008-10-23
Posts: 8

Re: Timer help

legolover wrote:

First, don't worry about a timer. Define a variable "time". When you want the timer to start, use a broadcast "BeginTimer".
[blocks]<when I receive[ start timer
<set{ time }to( 0
<repeat until><touching color[ red
<wait( .01 secsc>
<change{ time }by( .01
<end>
<stop script>[/blocks]

Thanks. I'll give it a try.
smile

Offline

 

#13 2008-10-25 17:26:28

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Timer help

nytram wrote:

Paddle2See wrote:

Can you share it so I can see why it isn't working?

Yes. Thank you.
smile


http://scratch.mit.edu/projects/nytram/302013

Okay, I identified a couple of problems in comments on the project.  Hopefully they will help.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#14 2008-10-25 22:44:11

nytram
Scratcher
Registered: 2008-10-23
Posts: 8

Re: Timer help

Paddle2See wrote:

nytram wrote:

Paddle2See wrote:

Can you share it so I can see why it isn't working?

Yes. Thank you.
smile


http://scratch.mit.edu/projects/nytram/302013

Okay, I identified a couple of problems in comments on the project.  Hopefully they will help.

Perfect. Thank you.
smile

Offline

 

#15 2008-10-26 05:28:55

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Timer help

legolover wrote:

First, don't worry about a timer. Define a variable "time". When you want the timer to start, use a broadcast "BeginTimer".

Alternatively, still using a variable called time:

When I recieve "Start Timer"
Reset Timer
Repeat until touching colour red
set "Time"="timer"


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

Board footer