Discuss Scratch

ToyStoryFan265
Scratcher
17 posts

Timer

I need help with increasing a timer if the sprite is clicked 5 times in a row before it moves to another position.
EDawg2011
Scratcher
1000+ posts

Timer

when this sprite clicked
change [time v] by (-15)
if <[0] > (time)> then
change [clicks v] by (1)
else
set [clicks v] to [0]
end
set [time v] to [0]
if <(clicks) > [4]> then
...
end
when green flag clicked
set [clicks v] to [0]
forever
wait (0) secs//Wait 1 frame; the wait block is a bit inaccurate and projects run at 30 frames per second.
change [time v] by (1)
end

or

when this sprite clicked
if <(timer) > [0.5]> then
set [clicks v] to [0]
else
change [clicks v] by (1)
end
reset timer
if <(clicks) > [4]> then
...
end
ToyStoryFan265
Scratcher
17 posts

Timer

It's not working. I'm making a game where you try to click the sprite as many times as possible in 30 seconds. What i'm trying to do is that if you you click the sprite 5 times before it randomly moves to a new location, the timer increases by 3.
DaveyLovesCoding
Scratcher
15 posts

Timer

You could try:

when green flag clicked
set [time v] to (30)
repeat until <(time) = [0]>
change [time v] by ((0) - (timer))
end

when green flag clicked
repeat until <(time) = [0]>
wait (stay in one position time) secs
go to [random position v]
end

when this sprite clicked
change [clicks v] by (1)
if <(clicks) > [4]> then // greater than 4 so 5 and above
change [time v] by (3)
end

NOTE: This is severely not optimized. I hope this helps, but you can definitely ask if you need more specific code.

EDIT: The code definitely does not work, specifically the “change time by 0 - timer” (it just keeps subtracting the timer and it goes down very fast), so if anybody else can solve this, it would be much appreciated.

Last edited by DaveyLovesCoding (Feb. 28, 2024 02:07:18)

commieolive
Scratcher
14 posts

Timer

Sorry but I don't know how to do the blocks thing so I'm just gonna type this

When Start Clicked:
set (timer) to 30
repeat until (timer<1)
wait 1 second
change (timer) by -1
stop (all)

When Start Clicked
repeat forever:
wait (however many you want) seconds
go to (random position)
set (this time's clicks) to 0

When this sprite clicked:
change (total clicks) by 1
change (this time's clicks) by 1
if (this time's clicks=5)
change (timer) by 3
ToyStoryFan265
Scratcher
17 posts

Timer

Nothing's working, i'm getting really stumped by this.
DaveyLovesCoding
Scratcher
15 posts

Timer

One more try:

when green flag clicked
set [time v] to (30)
repeat until <(time) = [0]>
wait until <(timer) > [1]>
change [time v] by (1)
reset timer
end

when green flag clicked
repeat until <(time) = [0]>
wait (stay in one position time) secs
go to [random position v]
end

when this sprite clicked
change [clicks v] by (1)
if <(clicks) > [4]> then // greater than 4 so 5 and above
change [time v] by (3)
end

This might work.

Last edited by DaveyLovesCoding (Feb. 28, 2024 14:28:03)

ToyStoryFan265
Scratcher
17 posts

Timer

I'll try this, but I already have the timer working. I just need it to increase by 3 seconds if the sprite is clicked before it moves to a new position, and then the clicks reset.
ToyStoryFan265
Scratcher
17 posts

Timer

It kinda works, but after I click 5 times, it keeps increasing every time I click. I want the amount of clicks to reset to 0 every time it moves.
DaveyLovesCoding
Scratcher
15 posts

Timer

ToyStoryFan265 wrote:

It kinda works, but after I click 5 times, it keeps increasing every time I click. I want the amount of clicks to reset to 0 every time it moves.

I forgot to add that feature lol

wait (some amount of time) secs
go to [random position v]
set [clicks v] to [0]

If you add that, it might help. However, it would help if I could see your code so I can see what it looks like.
ToyStoryFan265
Scratcher
17 posts

Timer

Thanks, I got it working! I finished the beta because of your help! https://scratch.mit.edu/projects/972023661/
DaveyLovesCoding
Scratcher
15 posts

Timer

Happy to help!

Powered by DjangoBB