Discuss Scratch

DNQ_brwn
Scratcher
12 posts

Adding a cooldown to In-game Button scripts

Hi, I'm working on a remaster of fnajs1, how do I add a cooldown do this script so it doesn't glitch?



lion334
Scratcher
100+ posts

Adding a cooldown to In-game Button scripts

Greetings!


There's Multiple ways to do so. I'll explain the easiest here to keep this message brief and short.

So you're using
when this sprite clicked

First, we gotta clear what a “Sprite click” means. Basically it means that the Mouse Pointer is on the Sprite itself and the left mouse button is pressed. We can resemble this with the following blocks:
<mouse down?> //Mouse Left Button Pressed?
<touching [Mouse Pointer v] ?> //Is the Mouse on me?

Out of these two statements we can form a boolean:
<<mouse down?> and <touching [Mouse Pointer v] ?>>

And finally, we can form the final result:
when green flag clicked //You can also use "If I start as a clone" if you're planning on getting a clone clicked
forever
if <<mouse down?> and <touching [Mouse Pointer v] ?>> then
Your Code
wait (5) secs //This is your cooldown
end
end

Alternatively you can use
when green flag clicked
forever
wait until <<mouse down?> and <touching [Mouse Pointer v] ?>>
Your Code
wait (5) secs //This is your cooldown
end




Sincerely, lion334

Hi, I'm Mirau or lion334

Made some cool game a while ago: You're not gonna click it though… right?


platypus3333
Scratcher
37 posts

Adding a cooldown to In-game Button scripts

lion334 wrote:

-snip-
You have to use the second option. The if statement won't stop being checked by the wait () seconds block.

Last edited by platypus3333 (June 14, 2023 15:16:28)


Hi! I'm platypus3333, but you can just call me plat. I am such a big splatoon fan with almost 1,000 hours in the series(I generally only have 2ish hours per week so it's relatively a lot.) I have beaten IA3, After Alterna, and low hack Eight's palette. I am really into analytical and theoretical stuff such as third kit possibilities, best way to end updates in 3, and what splatoon 4 could look like and what it really needs. I main Ttek splattershot, 89, Vdualies, carbon deco, and custom jr. I like basically any weapon with reasonable paint and some method of reliably getting splats. Currently I am working on making theoretical third kits for every single weapon.
lion334
Scratcher
100+ posts

Adding a cooldown to In-game Button scripts

platypus3333 wrote:

lion334 wrote:

-snip-
You have to use the second option. The if statement won't stop being checked by the wait () seconds block.
Actually… it will.

Having the code made using
when green flag clicked
or
when I start as a clone

will automatically make this block getting played once, therefore you cannot get two “true” returns in the mouse-click boolean. Having the Block repeat itself makes it able that you can use the “is clicked” again, once the cooldown (in my example 5 seconds) ran out.

I think you meant this block:
when I receive [ v]


So yea, both methods work just fine.

Hi, I'm Mirau or lion334

Made some cool game a while ago: You're not gonna click it though… right?


DNQ_brwn
Scratcher
12 posts

Adding a cooldown to In-game Button scripts

lion334 wrote:

platypus3333 wrote:

lion334 wrote:

-snip-
You have to use the second option. The if statement won't stop being checked by the wait () seconds block.
Actually… it will.

Having the code made using
when green flag clicked
or
when I start as a clone

will automatically make this block getting played once, therefore you cannot get two “true” returns in the mouse-click boolean. Having the Block repeat itself makes it able that you can use the “is clicked” again, once the cooldown (in my example 5 seconds) ran out.

I think you meant this block:
when I receive [ v]


So yea, both methods work just fine.


Thanks but I meant the when sprite clicked block
when this sprite clicked
if <(costume #) = [X]> then
switch costume to [Y v]
broadcast [A v]

else
switch costume to [Z v]
broadcast [B v]
end

When you click the button, it will glitch the costume animation if you keep clicking the button, that kind of glitch basically.

Last edited by DNQ_brwn (June 14, 2023 16:22:40)

lion334
Scratcher
100+ posts

Adding a cooldown to In-game Button scripts

DNQ_brwn wrote:

lion334 wrote:

platypus3333 wrote:

lion334 wrote:

-snip-
You have to use the second option. The if statement won't stop being checked by the wait () seconds block.
Actually… it will.

Having the code made using
when green flag clicked
or
when I start as a clone

will automatically make this block getting played once, therefore you cannot get two “true” returns in the mouse-click boolean. Having the Block repeat itself makes it able that you can use the “is clicked” again, once the cooldown (in my example 5 seconds) ran out.

I think you meant this block:
when I receive [ v]


So yea, both methods work just fine.


Thanks but I meant the when sprite clicked block
when this sprite clicked
if <(costume #) = [X]> then
switch costume to [Y v]
broadcast [A v]

else
switch costume to [Z v]
broadcast [B v]
end

When you click the button, it will glitch the costume animation if you keep clicking the button, that kind of glitch basically.
Yea…. thats the Question of the post I answered in my first response I think. Must be a misunderstanding.

Basically in my first Post I'm explaining a fix for the Problem. It works the same as the Script you're trying to use, except it has a cooldown. Else it's exactly the same, it detects when a Sprite is clicked and then executes the code - but with a cooldown.

Last edited by lion334 (June 14, 2023 19:08:34)


Hi, I'm Mirau or lion334

Made some cool game a while ago: You're not gonna click it though… right?


Mave_LOLL
Scratcher
1 post

Adding a cooldown to In-game Button scripts

how do I set a cool down for a move for a character?
lion334
Scratcher
100+ posts

Adding a cooldown to In-game Button scripts

Mave_LOLL wrote:

how do I set a cool down for a move for a character?

I reckon you've got a Movement-Script:
Movement Script

Therefore, my version of doing a cooldown would be this:
when green flag clicked
forever
if <[0] < (Cooldown)> then
wait (0.1) secs
change [Cooldown v] by (-0.1) //You can't just do "Wait Cooldown Seconds" and then set it to 0, as this would mean that if a Cooldown is added ontop of another, it would be ignored.
end
end

if <(Cooldown) < [0.01]> then //Updated Movement Script
Movement Script
end

set [Cooldown v] to [2] //Set a fixed cooldown

change [Cooldown v] by (2) //Or add to a cooldown


This should solve your problem.

Sincerely,
lion334

Hi, I'm Mirau or lion334

Made some cool game a while ago: You're not gonna click it though… right?


GamerMYM
Scratcher
100+ posts

Adding a cooldown to In-game Button scripts

.]

Last edited by GamerMYM (March 31, 2024 14:10:14)


Hey! It’s GamerMYM here! You found me! —I'm a gamer who loves to play all sorts of games (appropriate), but I'm especially fond of building games. I'm always up for a challenge, and I love working together with others to complete tasks and achieve goals! — I'm a developer who loves to create fun and engaging games for players of all ages. I'm especially passionate about building and designing new worlds for players to explore. I'm also a big fan of collaborating with other developers to create even better games. I'm always looking for new and innovative ways to improve the Scratch experience. I'm a big believer in the community and I love interacting with people and hearing their feedback. I'm also a team player and I'm always willing to go the extra mile to help my team succeed. Remember, Never give up, & DOnt quIT. #StayCool
Itzommy_YT
Scratcher
2 posts

Adding a cooldown to In-game Button scripts

Thank you that really helps!
Itzommy_YT
Scratcher
2 posts

Adding a cooldown to In-game Button scripts

GamerMYM wrote:

.]
DNQ_brwn
Scratcher
12 posts

Adding a cooldown to In-game Button scripts

I'm going to have to close the topic since the problem is already solved.

Powered by DjangoBB