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* 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
Any way with variables?
Offline
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
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)
Offline
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* 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.
Offline
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)
Offline
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) secsOr 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
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) secsOr you could make it complex. (Example in my Fireworks Game lists and player sensor)
Oh duh.
I forgot that. XD
Offline
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
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) endInstead of broadcasts for pausing and resuming, you should use variables. For the pause and resume button, you could add/replace it with this script:
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
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) endInstead 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 endLooking 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 endI would use this method just to make it (almost) perfect timing.
Last edited by Splodgey (2012-02-18 03:30:31)
Offline
Actually Splodgey, it will pause even during the wait (0.99) secs. 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)> endI 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
Magnie wrote:
Actually Splodgey, it will pause even during the wait (0.99) secs. 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)> endI 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
Calm down everyone, i just had a stray script. It's good now.
Offline
rdococ wrote:
Magnie wrote:
Actually Splodgey, it will pause even during the wait (0.99) secs. 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)> endI 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.
Offline