Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Online player counter
- speb_official
-
Scratcher
3 posts
Online player counter
genuinely just need to know how to make a player counter work for a game I'm making
- Cool_Dude2022
-
Scratcher
500+ posts
Online player counter
genuinely just need to know how to make a player counter work for a game I'm making
This is almost impossible to do as the player can close the game in many ways that are undetectable. You can detect if the player starts the project by detecting the green flag or if they clicked start, but it's impossible to detect a player leaves the game.
- yadayadayadagoodbye
-
Scratcher
1000+ posts
Online player counter
Rather than detecting if the player leaves, you should, at fixed intervals, detect if a player is still there. Every once in a while, request all players to set a cloud variable. You can then detect how many players did so (for example, they could simply add 1 to it), and that there would be your player count.
- Cool_Dude2022
-
Scratcher
500+ posts
Online player counter
Rather than detecting if the player leaves, you should, at fixed intervals, detect if a player is still there. Every once in a while, request all players to set a cloud variable. You can then detect how many players did so (for example, they could simply add 1 to it), and that there would be your player count.
Yes, but once they close the game, then that script stops working resulting in the variable staying the same and it produces a false positive.
Last edited by Cool_Dude2022 (Sept. 23, 2024 12:33:39)
- GamesReinvented
-
New Scratcher
100+ posts
Online player counter
The variable wouldn't stay the same, as since they aren't changing the variable anymore, they would no longer be counted as an active player.Rather than detecting if the player leaves, you should, at fixed intervals, detect if a player is still there. Every once in a while, request all players to set a cloud variable. You can then detect how many players did so (for example, they could simply add 1 to it), and that there would be your player count.
Yes, but once they close the game, then that script stops working resulting in the variable staying the same and it produces a false positive.
Last edited by GamesReinvented (Sept. 23, 2024 12:44:51)
- Cool_Dude2022
-
Scratcher
500+ posts
Online player counter
The variable wouldn't stay the same, as since they aren't changing the variable anymore, they would no longer be counted as an active player.Rather than detecting if the player leaves, you should, at fixed intervals, detect if a player is still there. Every once in a while, request all players to set a cloud variable. You can then detect how many players did so (for example, they could simply add 1 to it), and that there would be your player count.
Yes, but once they close the game, then that script stops working resulting in the variable staying the same and it produces a false positive.
It's like stopping the game while increasing a variable. Once you stop the game, the variable doesn't increase anymore. Or in this case, once you stop the game then that “every once in a while” will not appear and not cause the player counter variable to decrease therefore resulting in a false positive.
Here's a demonstration: https://scratch.mit.edu/projects/1072313836/editor
- Discussion Forums
- » Help with Scripts
-
» Online player counter