Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Detecting how many cps (clicks per second)
- Zero0111
-
100+ posts
Detecting how many cps (clicks per second)
If I wanted to detect how many clicks per second someone has when they click the sprite how would I do that? (I already tried 3 ways but none of worked because the CPS variable always stays at 1 and I am tryna detect how many clicks variable is at when CPS variable goes to 0)
- Coder046
-
100+ posts
Detecting how many cps (clicks per second)
Try using this:
This updates for every click, using the gap between clicks to calculate how fast the last click was.
You can round as necessary. For example, if you wanted to round it to the nearest hundredth, you would do this:
when green flag clicked
forever
set [last click v] to (timer)
wait until <mouse down?>
set [CPS v] to ((1)/((timer)-(last click)))
wait until <not<mouse down?>>
end
This updates for every click, using the gap between clicks to calculate how fast the last click was.
You can round as necessary. For example, if you wanted to round it to the nearest hundredth, you would do this:
set [CPS v] to ((round((CPS)*(100)))/(100)
- supergamestar
-
51 posts
Detecting how many cps (clicks per second)
That's an awesome approach for calculating the clicks per second! Another one I came up with uses the idea of decaying average or a rolling average. Basically have a counter for clicks, and every 0.1 seconds you take away 10% of the counter. This means the click counter approaches a steady state that equals the user's clicks per second, but you don't get spikes or quick drops. For instance if I do click click pause a second, click click pause a second, the click rate hovers between 1 and 2 rather than having spikes up to 5 or 6.
Here's what that approach looks like:
(First time typing in scratch blocks in a comment so forgive me if I messed up haha)
The rounding idea is very good too. If you add that to mine, it's probably best to use a separate variable for it, after the set cps block, so that it doesn't interfere with the decay process.
Here's what that approach looks like:
when green flag clicked
set [cps] to [0]
forever
wait (0.1) secs
set [cps] to ((cps) * (0.9))
end
when this sprite clicked
change [cps] by 1
(First time typing in scratch blocks in a comment so forgive me if I messed up haha)
The rounding idea is very good too. If you add that to mine, it's probably best to use a separate variable for it, after the set cps block, so that it doesn't interfere with the decay process.
- Coder046
-
100+ posts
Detecting how many cps (clicks per second)
That would work!
[Also, you did great using scratchblocks. A couple things you could've done there:
- Add _v (the underscore is supposed to be a visible space) to the end of “cps” to make it part of a drop-down, like it normally would.
- Put the one in parentheses. This should fix the red block.
- Finally, do you see the little check mark at the top of the commenting part? That's so that you can see what your comment would actually look like. It's extremely useful.]
[Also, you did great using scratchblocks. A couple things you could've done there:
- Add _v (the underscore is supposed to be a visible space) to the end of “cps” to make it part of a drop-down, like it normally would.
- Put the one in parentheses. This should fix the red block.
- Finally, do you see the little check mark at the top of the commenting part? That's so that you can see what your comment would actually look like. It's extremely useful.]
when green flag clicked
set [cps v] to (0)
forever
wait (0.1) secs
set [cps v] to ((cps)*(0.9))
end
when this sprite clicked
change [cps v] by (1)
- MrNanners
-
100+ posts
Detecting how many cps (clicks per second)
try not to use the
wait until <>block multiple times, as it takes a frame to update I believe, so having two will limit the fastest clicking count to 10 or 15 clicks per second, since it's one frame to hit the block, one frame to detect its boolean value, then another frame to detect the other wait block's value.
when this sprite clickedthis will result in the most accurate cps counter.
set [cps v] to ((1) / (timer))
reset timer
Last edited by MrNanners (Jan. 19, 2022 13:31:02)
- ExtraMental
-
100+ posts
Detecting how many cps (clicks per second)
Please do not necropost. hi
- DWD_Duck
-
8 posts
Detecting how many cps (clicks per second)
None of these seem to work for me for some reason, they somewhat work until I click sorta fast, and it reaches 30 cps, so idk what’s up.
- roye2014
-
63 posts
Detecting how many cps (clicks per second)
I have somewhat a clue on how to do this but I’ll come back later with help!
Last edited by roye2014 (March 20, 2025 17:35:34)
- projectkrish
-
37 posts
Detecting how many cps (clicks per second)
Just do this
when this sprite clicked
change [CPS v] by (1)
wait (1) secs
say (CPS)
- Discussion Forums
- » Help with Scripts
-
» Detecting how many cps (clicks per second)