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

#1 2012-08-18 18:41:15

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Pausing timers

Is there any way for me to "pause" a timer? I'm making a game where the score is based off of a timer, and I don't want someone to cheat by pausing the game and letting the timer add to their score unfairly. I've tried making something like this, but it won't work:

when I receive [Paused v]
if <(paused) = [true]>
set [remember timer v] to (timer)
set [Score v] to (Score)
else
set [Score v] to ((round (timer)) + ((Enemies killed) * (5))
end
Ack! Now even the scratchblocks aren't working! Oh, well. At the bottom, it's supposed to say ((round (timer)) + ((Enemies killed) * (5)).

Does anyone have any suggestions as to how I could attempt this?  hmm

Last edited by Zangooser (2012-08-18 21:21:33)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#2 2012-08-18 18:53:56

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Pausing timers

dont use the normal timer, it goes on constantly. Instead use this

when gf clicked
forever
if <(paused) = (0)>
change [timer v] by (0.1)
wait (0.1) secs
and when you pause set "paused" to 1, and when you unpause set it to 0


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#3 2012-08-18 19:12:55

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Pausing timers

Zangooser wrote:

Is there any way for me to "pause" a timer? I'm making a game where the score is based off of a timer, and I don't want someone to cheat by pausing the game and letting the timer add to their score unfairly. I've tried making something like this, but it won't work:

when I receive [Paused v]
if <(paused) = [true]>
set [remember timer v] to (timer)
set [Score v] to (Score)
else
set [Score v] to ((round (timer)) + ((Enemies killed) * (5)))
end
Ack! Now even the scratchblocks aren't working! Oh, well. At the bottom, it's supposed to say ((round (timer)) + ((Enemies killed) * (5)).

Does anyone have any suggestions as to how I could attempt this?  hmm

Fixed.

Other than that, my only suggestion is to do what zammer990 told you to do. Sorry about not constructively adding to the conversation.
sad

Last edited by ErnieParke (2012-08-18 19:26:11)


http://i46.tinypic.com/35ismmc.png

Offline

 

#4 2012-08-18 19:52:43

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Pausing timers

No, you shouldn't do what zammer990 said, because due to the scratchblocks delay, it'll be way off. What you should do is this:

when gf clicked
set [timer v] to [0]
forever
if <not<(paused)=[1]>>
reset timer
wait until <<(timer) > (1)>or <(timer) = [1]>>
change [timer v] by (1)
end

Offline

 

#5 2012-08-18 19:58:21

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Pausing timers

TorbyFork234 wrote:

No, you shouldn't do what zammer990 said, because due to the scratchblocks delay, it'll be way off. What you should do is this:

when gf clicked
set [timer v] to [0]
forever
if <not<(paused)=[1]>>
reset timer
wait until <<(timer) > (1)>or <(timer) = [1]>>
change [timer v] by (1)
end

I noticied that, but I hadn't thought of this script. I'm still learning.  smile


http://i46.tinypic.com/35ismmc.png

Offline

 

#6 2012-08-18 20:03:23

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Pausing timers

ErnieParke wrote:

TorbyFork234 wrote:

No, you shouldn't do what zammer990 said, because due to the scratchblocks delay, it'll be way off. What you should do is this:

when gf clicked
set [timer v] to [0]
forever
if <not<(paused)=[1]>>
reset timer
wait until <<(timer) > (1)>or <(timer) = [1]>>
change [timer v] by (1)
end

I noticied that, but I hadn't thought of this script. I'm still learning.  smile

you could also do increments of 0.5 instead of 1, to make it be a little more exact, because someone could still get 1.9x the point by skillfully pressing pause at the right moment every second.

Offline

 

#7 2012-08-18 20:14:30

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Pausing timers

TorbyFork234 wrote:

ErnieParke wrote:

TorbyFork234 wrote:

No, you shouldn't do what zammer990 said, because due to the scratchblocks delay, it'll be way off. What you should do is this:

when gf clicked
set [timer v] to [0]
forever
if <not<(paused)=[1]>>
reset timer
wait until <not <(timer) < [1]>>
change [timer v] by (1)
end

I noticied that, but I hadn't thought of this script. I'm still learning.  smile

you could also do increments of 0.5 instead of 1, to make it be a little more exact, because someone could still get 1.9x the point by skillfully pressing pause at the right moment every second.

Just to let you know, you could have shortened the script a bit. Just look above. ^^


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2012-08-18 20:32:53

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Pausing timers

If you use 0.05 seconds on the wait it works fine


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#9 2012-08-20 07:06:24

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

Re: Pausing timers

My suggestion would be to do this:

1) Use the timer (its more exact).
2) Record the time paused for.

set [delay v] to (0)
reset timer
repeat until <(game) = [over]>
if <(paused) = [true]>
set [start v] to (timer)
wait until <(paused) = [false]>
set [delay v] to ((delay) + ((timer) - (start)))
end
end
end

when gf clicked
forever
if <(paused) = [true]>
set [timer v] to ((timer) - (delay))

Last edited by Prestige (2012-08-20 07:07:12)


"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

 

#10 2012-09-27 07:47:35

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

Re: Pausing timers


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

Offline

 

Board footer