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

#1 2012-02-13 17:16:55

ScratchBotEater
New Scratcher
Registered: 2012-01-25
Posts: 4

Script that times you for 2 minutes

Hi, I made a great game called Scratch Snatch! It WAS going to be my first project, but then scratch died down, and I had to restart the WHOLE thing! *gives evil eye*  mad  Anyways, when I was doing it again, there were some glitches, I fixed them. Then I had 2 scripts left. Yes, you heard me right.  But then, unfortunately  I couldn't figure out how I made a timer. This is what I did, but then it didn't work!  I did: When I receive [broadcast], Set Remaining Seconds too 120, [forever] Wait one second, Change Remaining seconds my -1, [end forever.] Is it wrong in any way?

Offline

 

#2 2012-02-13 17:23:08

MrMonk999
Scratcher
Registered: 2011-12-17
Posts: 500+

Re: Script that times you for 2 minutes

there already is timer block in the sensing section.
try

when i receive 
reset timer 
wait until (timer = 120)
do stuff


http://i.imgur.com/CAMJe.png

Offline

 

#3 2012-02-13 17:40:50

ScratchBotEater
New Scratcher
Registered: 2012-01-25
Posts: 4

Re: Script that times you for 2 minutes

Any way with variables?  tongue

Offline

 

#4 2012-02-13 18:32:25

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Script that times you for 2 minutes

I would assume your way should work, I see no reason it shouldn't.

when gf clicked
set [clock v] to (120)
repeat until <(clock) < (1)>
    wait (0.99) secs
    change [clock v] by (-1)
end
broadcast [timer finished v]

Offline

 

#5 2012-02-13 21:24:37

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Script that times you for 2 minutes

All of those will work, or you can do:

when gf clicked
reset timer
repeat until <(timer) > [120]>
  set [timeleft v] to <[120] - (timer)>
end

Last edited by AtomicBawm3 (2012-02-13 21:26:33)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#6 2012-02-13 21:33:48

Luxturna
Scratcher
Registered: 2011-04-24
Posts: 38

Re: Script that times you for 2 minutes

ScratchBotEater wrote:

Hi, I made a great game called Scratch Snatch! It WAS going to be my first project, but then scratch died down, and I had to restart the WHOLE thing! *gives evil eye*  mad  Anyways, when I was doing it again, there were some glitches, I fixed them. Then I had 2 scripts left. Yes, you heard me right.  But then, unfortunately  I couldn't figure out how I made a timer. This is what I did, but then it didn't work!  I did: When I receive [broadcast], Set Remaining Seconds too 120, [forever] Wait one second, Change Remaining seconds my -1, [end forever.] Is it wrong in any way?

Maybe
[When GF clicked]
[Set (variable) to 120]
[--Repeat until (<variable=0>)]
[Change (variable) by 1]
[Wait (1) second]
--
forever
  [--if (variable=0)]
   [Stop all]
  --
--

I  hope that helps, even though that's unclear. I forget/ don't know how to do the blocks.


http://scratch.mit.edu/static/icons/buddy/782569_med.png?t=2012-03-10+00%3A38%3A57

Offline

 

#7 2012-02-13 22:30:13

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: Script that times you for 2 minutes

Quite simple really.

when gf clicked
set (time) to [120]
repeat until <(time) = [0]>
change (time) by [-1]
wait [1] secs

Last edited by CheeseMunchy (2012-02-14 10:15:53)


6418,

Offline

 

#8 2012-02-14 08:33:21

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Script that times you for 2 minutes

CheeseMunchy wrote:

Quite simple really.

when gf clicked
set (time) to [120]
repeat until <(time) = [0]>
change (time) by [-1]

No, That would be 3 seconds in Scratch player, 4 seconds in java and 0.0012 seconds in flash. You need a

wait (1) secs
Or you could make it complex. (Example in my Fireworks Game lists and player sensor)

Last edited by Splodgey (2012-02-14 08:34:08)

Offline

 

#9 2012-02-14 10:15:08

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: Script that times you for 2 minutes

Splodgey wrote:

CheeseMunchy wrote:

Quite simple really.

when gf clicked
set (time) to [120]
repeat until <(time) = [0]>
change (time) by [-1]

No, That would be 3 seconds in Scratch player, 4 seconds in java and 0.0012 seconds in flash. You need a

wait (1) secs
Or you could make it complex. (Example in my Fireworks Game lists and player sensor)

Oh duh.
I forgot that. XD


6418,

Offline

 

#10 2012-02-17 09:23:02

jimyandboby13
New Scratcher
Registered: 2012-02-17
Posts: 1

Re: Script that times you for 2 minutes

I have a problem. I have a game I'm trying to perfect: Adventure Mormon. It needs a timer. I've made a variable "time" but I need to know how to pause it when you hit the pause button. How would I do that? I already have 2 broadcasts: Pause and Resume. What now?

Offline

 

#11 2012-02-17 09:48:03

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Script that times you for 2 minutes

jimyandboby13 wrote:

I have a problem. I have a game I'm trying to perfect: Adventure Mormon. It needs a timer. I've made a variable "time" but I need to know how to pause it when you hit the pause button. How would I do that? I already have 2 broadcasts: Pause and Resume. What now?

when gf clicked
set [time v] to (120)
set [paused? v] to (0)
repeat until <(time) = (0)>
    wait until <(paused?) = (0)>
    wait (0.99) secs
    change [time v] by (-1)
end
Instead of broadcasts for pausing and resuming, you should use variables. For the pause and resume button, you could add/replace it with this script:

(Modified from here.)
when gf clicked
set [paused? v] to (0)
forever
    wait until <<touching [mouse-pointer v]?> and <mouse down?>>
    set [paused? v] to ((1) - (paused?))
    wait until <<not <touching [mouse-pointer v]?>> or <not <mouse down?>>>

Last edited by Magnie (2012-02-17 09:48:41)

Offline

 

#12 2012-02-18 03:29:48

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Script that times you for 2 minutes

Magnie wrote:

jimyandboby13 wrote:

I have a problem. I have a game I'm trying to perfect: Adventure Mormon. It needs a timer. I've made a variable "time" but I need to know how to pause it when you hit the pause button. How would I do that? I already have 2 broadcasts: Pause and Resume. What now?

when gf clicked
set [time v] to (120)
set [paused? v] to (0)
repeat until <(time) = (0)>
    wait until <(paused?) = (0)>
    wait (0.99) secs
    change [time v] by (-1)
end
Instead of broadcasts for pausing and resuming, you should use variables. For the pause and resume button, you could add/replace it with this script:

(Modified from here.)
when gf clicked
set [paused? v] to (0)
forever
    wait until <<touching [mouse-pointer v]?> and <mouse down?>>
    set [paused? v] to ((1) - (paused?))
    wait until <<not <touching [mouse-pointer v]?>> or <not <mouse down?>>>

There is one problem with that. If they pause when it is waiting 0.99 seconds it won't pause. It could be fixed like this, but it is a little complex:

when gf clicked
set [player v] to [Scratch Player]
broadcast [((0)/(0))]
set [player v] to [Java]
Obsolete!
set [player v] to [flash]
See the wiki for more information on "online/offline detection"

when gf clicked
wait (0.1) secs
set [timer counter v] to [0]
set [time v] to [120]
if <(player) = [scratch player]>
 repeat until <(time) = [0]>
  wait until <(paused?) = (0)>
  change [timer counter v] by (1)
  if <(timer counter) = [40]>
   change [time v] by (-1)
   set [timer counter v] to [0]
  end
 end
else
 if <(player) = [java]>
  repeat until <(time) = [0]>
   wait until <(paused?) = (0)>
   change [timer counter v] by (1)
   if <(timer counter) = [30]>
    change [time v] by (-1)
    set [timer counter v] to [0]
   end
  end
else
 repeat until <(time) = [0]>
  wait until <(paused?) = (0)>
  change [timer counter v] by (1)
  if <(timer counter) = [100000]>
   change [time v] by (-1)
   set [timer counter v] to [0]
  end
 end
Looking at it now it seems way to long. There is another way. That isn't quite so long. It uses the first script too but slightly differently:
when gf clicked
set [player v] to [1]
broadcast [((0)/(0))]
set [player v] to [2]
Obsolete!
set [player v] to [3]
add [40] to [player speed v]
add [30] to [player speed v]
add [100000] to [player speed v]
Those must be in a list.
when gf clicked
wait (0.1) secs
set [timer counter v] to [0]
set [time v] to [120]
repeat until <(time) = [0]>
 wait until <(paused?) = [0]>
 change [timer counter v] by (1)
 if <(timer counter) = (item (player) of [player speed v])>
  change [time v] by (-1)
  set [timer counter v] to [0]
 end
end
I would use this method just to make it (almost) perfect timing.

Last edited by Splodgey (2012-02-18 03:30:31)

Offline

 

#13 2012-02-18 10:18:11

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Script that times you for 2 minutes

Actually Splodgey, it will pause even during the wait (0.99) secs.  smile  Or at least, when you press the pause button during the wait, then it'll finish the wait, decrease by one then it'll stop.

Though I guess this would be better:

when gf clicked
set [time v] to (120)
set [paused? v] to (0)
repeat until <(time) = (0)>
    change [time v] by (-1)
    wait (0.99) secs
    wait until <(paused?) = (0)>
end
I just switched the change, wait, and wait-until blocks around. So while it's "waiting" and if the user pauses the timer during the wait, then it won't decrease the time.

Last edited by Magnie (2012-02-18 10:25:49)

Offline

 

#14 2012-02-19 10:01:05

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Script that times you for 2 minutes

Magnie wrote:

Actually Splodgey, it will pause even during the wait (0.99) secs.  smile  Or at least, when you press the pause button during the wait, then it'll finish the wait, decrease by one then it'll stop.

Though I guess this would be better:

when gf clicked
set [time v] to (120)
set [paused? v] to (0)
repeat until <(time) = (0)>
    change [time v] by (-1)
    wait (0.99) secs
    wait until <(paused?) = (0)>
end
I just switched the change, wait, and wait-until blocks around. So while it's "waiting" and if the user pauses the timer during the wait, then it won't decrease the time.

But then it won't wait one second before the time at 120 decreases by 1 at the first. So either you need to replace 120 with 121 or put a "wait (0.99) secs" before the repeat until.

Offline

 

#15 2012-02-19 19:59:18

ScratchBotEater
New Scratcher
Registered: 2012-01-25
Posts: 4

Re: Script that times you for 2 minutes

Calm down everyone, i just had a stray script. It's good now.

Offline

 

#16 2012-02-19 21:12:38

Mokat
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: Script that times you for 2 minutes

You put a stop script inside the forever block, right? If so, that's your problem.


http://www.eggcave.com/egg/977371.pnghttp://www.eggcave.com/egg/977376.pnghttp://www.eggcave.com/egg/1005291.pnghttp://www.eggcave.com/egg/996745.png

Offline

 

#17 2012-02-20 10:53:25

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Script that times you for 2 minutes

rdococ wrote:

Magnie wrote:

Actually Splodgey, it will pause even during the wait (0.99) secs.  smile  Or at least, when you press the pause button during the wait, then it'll finish the wait, decrease by one then it'll stop.

Though I guess this would be better:

when gf clicked
set [time v] to (120)
set [paused? v] to (0)
repeat until <(time) = (0)>
    change [time v] by (-1)
    wait (0.99) secs
    wait until <(paused?) = (0)>
end
I just switched the change, wait, and wait-until blocks around. So while it's "waiting" and if the user pauses the timer during the wait, then it won't decrease the time.

But then it won't wait one second before the time at 120 decreases by 1 at the first. So either you need to replace 120 with 121 or put a "wait (0.99) secs" before the repeat until.

It's just a simple timer.  tongue

Offline

 

Board footer