Discuss Scratch

plasmaticatt
New Scratcher
14 posts

Button cooldowns

So, I'm trying to make a game where when you tap space while, say, examplesprite1 is touching examplesprite2, you get a point. If you press the button at any other time, you lose a point, and if you miss you also lose a point. The thing I'm worried about is, you can just hold down space; and even if you don't mean to, missing the spacebar key will result you in losing 7 points because it technically counted as holding it down. So, you lose a couple million points by holding down space bar. How do I set a cooldown? And while you're at it, can you guys tell me how to make a cooldown for clicking, too? Thanks.
blablablahello
Scratcher
1000+ posts

Button cooldowns

plasmaticatt wrote:

So, I'm trying to make a game where when you tap space while, say, examplesprite1 is touching examplesprite2, you get a point. If you press the button at any other time, you lose a point, and if you miss you also lose a point. The thing I'm worried about is, you can just hold down space; and even if you don't mean to, missing the spacebar key will result you in losing 7 points because it technically counted as holding it down. So, you lose a couple million points by holding down space bar. How do I set a cooldown? And while you're at it, can you guys tell me how to make a cooldown for clicking, too? Thanks.
add a
wait until <not <key [space v] pressed?>>
skywalker858347
Scratcher
100+ posts

Button cooldowns

blablablahello wrote:

plasmaticatt wrote:

So, I'm trying to make a game where when you tap space while, say, examplesprite1 is touching examplesprite2, you get a point. If you press the button at any other time, you lose a point, and if you miss you also lose a point. The thing I'm worried about is, you can just hold down space; and even if you don't mean to, missing the spacebar key will result you in losing 7 points because it technically counted as holding it down. So, you lose a couple million points by holding down space bar. How do I set a cooldown? And while you're at it, can you guys tell me how to make a cooldown for clicking, too? Thanks.
add a
wait until <not <key [space v] pressed?>>
Yes, you could also do these
when [space v] key pressed
change [points v] by (0)
because this isn't in a forever loop, it isn't as sensitive and acts as if you were typing, so there is a moment for you to take you finger off before it takes away a lot of points.

Same thing with clicking:
when this sprite clicked
do stuff
plasmaticatt
New Scratcher
14 posts

Button cooldowns

Unfortunately, the “wait until” script freezes the entire game while space is held. The “when space key pressed” also has no effect on the issue.
DeveloperTools
Scratcher
100+ posts

Button cooldowns

plasmaticatt wrote:

Unfortunately, the “wait until” script freezes the entire game while space is held. The “when space key pressed” also has no effect on the issue.
forever
if <key [key v] pressed?> then
set [lastpress v] to ((days since 2000) * [86400])
wait until <<not <key [key v] pressed?>> or <(((days since 2000) * [86400]) - (lastpress)) < [Change this to how quick the cooldown should be]>>
if <key [key v] pressed?> then
Punish the player for holding down the key!
end
plasmaticatt
New Scratcher
14 posts

Button cooldowns

Unfortunately, I really can't seem to get it; I think maybe sharing the project will help give you guys a better idea? https://scratch.mit.edu/projects/732538167/
DeveloperTools
Scratcher
100+ posts

Button cooldowns

plasmaticatt wrote:

Unfortunately, I really can't seem to get it; I think maybe sharing the project will help give you guys a better idea? https://scratch.mit.edu/projects/732538167/
Which example did you use??
plasmaticatt
New Scratcher
14 posts

Button cooldowns

Tried using yours, but the message got cut off and I couldn't see much of it. Also got lost a bit of the way there
plasmaticatt
New Scratcher
14 posts

Button cooldowns

Also just tried to do what you said, the only thing thats happening is the value of “lastpress” increasing
DeveloperTools
Scratcher
100+ posts

Button cooldowns

plasmaticatt wrote:

Also just tried to do what you said, the only thing thats happening is the value of “lastpress” increasing
I cant find anything that looks like my code inside the project so idk what ur doing wrong

Edit: Nevermind

Last edited by DeveloperTools (Sept. 20, 2022 15:44:07)

plasmaticatt
New Scratcher
14 posts

Button cooldowns

Aight, it's my passing period, I'll b back in a bit
DeveloperTools
Scratcher
100+ posts

Button cooldowns

plasmaticatt wrote:

Also just tried to do what you said, the only thing thats happening is the value of “lastpress” increasing
You put
<<not <key [space v] pressed?>> or <((days since 2000) * (86400)) < (lastpress)>>
Instead of:
<<not <key [space v] pressed?>> or <(((days since 2000) * (86400)) - (lastpress)) > [Cooldown]>>
DeveloperTools
Scratcher
100+ posts

Button cooldowns

DeveloperTools wrote:

plasmaticatt wrote:

Also just tried to do what you said, the only thing thats happening is the value of “lastpress” increasing
You put
<<not <key [space v] pressed?>> or <((days since 2000) * (86400)) < (lastpress)>>
Instead of:
<<not <key [space v] pressed?>> or <(((days since 2000) * (86400)) - (lastpress)) > [Cooldown]>>
Since the blocks spawn every second, I would recommend a value less than 1
plasmaticatt
New Scratcher
14 posts

Button cooldowns

Still isn't working.. I assume I have to define “lastpress,” but what exactly is it in the way you intend?
DeveloperTools
Scratcher
100+ posts

Button cooldowns

plasmaticatt wrote:

Still isn't working.. I assume I have to define “lastpress,” but what exactly is it in the way you intend?
“lastpress” doesn't need to be set as anything it already sets itself when u press space
msztr
Scratcher
100+ posts

Button cooldowns

when green flag clicked
forever
go to x: (0) y: (200)
repeat until <<key [space v] pressed>or<out of bounds>>
falling script
end
if <touching [detector]> then
change [score v] by (1)
else
change [score v] by (-1)
end
repeat until <out of bounds>
falling script
end
wait (cooldown) secs

Last edited by msztr (Sept. 20, 2022 21:03:15)

DeveloperTools
Scratcher
100+ posts

Button cooldowns

plasmaticatt wrote:

Still isn't working.. I assume I have to define “lastpress,” but what exactly is it in the way you intend?
You still have the operators incorrect.. You have to subtract “lastpress” from “days since 2000”
<(((days since 2000) * [86400]) - (lastpress)) > [cooldown]> // HAS TO BE >, NOT < (my original reply had the wrong inequality)

Last edited by DeveloperTools (Sept. 20, 2022 20:59:29)

DeveloperTools
Scratcher
100+ posts

Button cooldowns

Here's how it looks like in Scratch 3.0:

(Ignore the mouse down blocks, I'm currently writing this on mobile.)
plasmaticatt
New Scratcher
14 posts

Button cooldowns

it didnt work
msztr
Scratcher
100+ posts

Button cooldowns

Did you try my method?

Powered by DjangoBB