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

#1 2012-05-20 15:46:42

al33th3a
New Scratcher
Registered: 2012-05-20
Posts: 4

How can I set timer to count down, then do action

I need to set my game timer to count down, when it gets to 0:00 it should start over at the beginning if the game isn't completed with in time allowed.

Thanks in advance  big_smile ,
         Al33th3a

Offline

 

#2 2012-05-20 15:54:10

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: How can I set timer to count down, then do action

You can't have the timer count down. Make a timer variable and every 0.01 seconds change it by -0.01.


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#3 2012-05-20 15:59:41

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: How can I set timer to count down, then do action

when gf clicked
forever
change [time left v] by [-0.01]
wait [0.01] secs
if <(time left) = [0]>
broadcast [start game v]
end
This should work.

Last edited by sonicfan12p (2012-05-20 16:01:20)


Why are the secret organizations getting all the attention?  mad

Offline

 

#4 2012-05-20 16:04:34

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: How can I set timer to count down, then do action

al33th3a wrote:

I need to set my game timer to count down, when it gets to 0:00 it should start over at the beginning if the game isn't completed with in time allowed.

Thanks in advance  big_smile ,
         Al33th3a

Hey there Al33th3a!
As previously stated by sonicfan12p the timer cannot count down, but its really easy to do it yourself.
Firstly, choose how long you want the session to last, so if you want the game to count down a minute then you'd choose 60 seconds.
    Now create a new variable, call it countdown.
Then at the start of the game session, set countdown to 60 (or however long you want it to last)
Set timer to 0
Then, repeat until countdown = 0,

 Set [countdown] to ( 60 - round (timer) ) 
The round part can be found in the math functions, it just removes all of the decimals from the timer but you don't have to do this.

When countdown = 0, or timer = 60 then stop the game  smile

If you want the player to SEE the countdown, then just show the countdown variable  smile
  Hope this helps!

Last edited by Prestige (2012-05-20 16:05:09)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#5 2012-05-20 17:42:01

al33th3a
New Scratcher
Registered: 2012-05-20
Posts: 4

Re: How can I set timer to count down, then do action

I got my game timer to count down, but now i can't get it to stop at 0:00 and then rest back to beginning time or loop back to start of game.

Thanks for your help :B,
          Al33th3a

Offline

 

#6 2012-05-20 17:46:59

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: How can I set timer to count down, then do action

If you're using the equality operator ( = ) try using the less than/greater than operators ( < and >) since those are looking for a less specific condition. Often, the timer can go past the exact 0 second mark before the boolean can catch it.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#7 2012-05-20 18:17:42

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: How can I set timer to count down, then do action

You can also do this:

set [StartingTime v] to [10]
set [CountingTime v] to [0]
reset timer
repeat until <(CountingTime) < (0)>
set [CountingTime v] to (round((StartingTime) - (timer)))
end

Last edited by amcerbu (2012-05-20 18:18:37)

Offline

 

#8 2012-05-20 22:18:11

al33th3a
New Scratcher
Registered: 2012-05-20
Posts: 4

Re: How can I set timer to count down, then do action

I have my timer working perfectly, but i still can figure out how to make my game go to the very beginning, (the main menu), sorry for all the issues!

Thanks so much  smile ,
         Al33th3a

Offline

 

#9 2012-05-21 00:37:10

al33th3a
New Scratcher
Registered: 2012-05-20
Posts: 4

Re: How can I set timer to count down, then do action

I can get my backgrounds to switch, but when i get ___ points i need it to switch to a background called congrats, and i can't figure it out! can you help?

thank so very much  big_smile ,
       Al33th3a

Offline

 

#10 2012-05-21 10:01:44

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: How can I set timer to count down, then do action

forever <if points > whatever>
broadcast switch backround


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#11 2012-08-15 07:43:22

krzysiogawl01
Scratcher
Registered: 2012-05-02
Posts: 13

Re: How can I set timer to count down, then do action

Count Down Timer
Script:

when flag clicked//This can be changed.
reset timer
set [clock v] to []
set [time v] to [0]
ask [Days] and wait
change [time v] by ((answer) * (86400))
ask [Hours] and wait
change [time v] by ((answer) * (3600))
ask [Minutes] and wait
change [time v] by ((answer) * (60))
ask [Seconds] and wait
change [time v] by (answer)
ask [Milliseconds (If full seconds then put 000)] and wait
change [time v] by ((answer) / (1000))
reset timer
set [clock v] to (time)
repeat until <<(timer) = (time)> or <(timer) > (time)>>
  set [clock v] to ((time) - (timer))
end
forever
  set [clock v] to []
  set [time v] to []
  reset timer
  play sound [BellToll v] until done
(Display in seconds.milliseconds)

Last edited by krzysiogawl01 (2012-08-15 08:07:42)


Don't know how to make a 0s1s stopwatch?
http://scratch.mit.edu/static/icons/buddy/1350608_med.png

Offline

 

Board footer