how do you make a players online counter?
id: 462276
category: Help with Scripts
posts: 27
Nov 30, 2020 17:01:25
how do you make a players online counter?
view on scratch
view on legacy ocular
_THEBOSS_7
loading
i assume it is a simple script? just counting how many players are online w/cloud variables?
Nov 30, 2020 17:19:56
how do you make a players online counter?
view on scratch
view on legacy ocular
DerpyHead0
loading
TLDR: as just a player counter for your project, it's impossble. if this is for cloud multiplayer, keep reading
it's easy to detect when a player connects, but checking for a player disconnect is a lot more complicated, because it means the code stops running entirely. stop button detection won't work here either, since they could just close the page.
what you need is another player to keep track of the disconnected player, and for online players to constantly update a cloud variable. however, this maxes out at the amount of cloud variables you have (10 if i remember correctly) because multiple players sharing the same variable will cause issues as players with lag overwrite each other.
all this is fine for cloud multiplayer with a player limit, but just trying to use it to count any player on the project isn't possible.
it's easy to detect when a player connects, but checking for a player disconnect is a lot more complicated, because it means the code stops running entirely. stop button detection won't work here either, since they could just close the page.
what you need is another player to keep track of the disconnected player, and for online players to constantly update a cloud variable. however, this maxes out at the amount of cloud variables you have (10 if i remember correctly) because multiple players sharing the same variable will cause issues as players with lag overwrite each other.
all this is fine for cloud multiplayer with a player limit, but just trying to use it to count any player on the project isn't possible.
Nov 30, 2020 17:27:31
how do you make a players online counter?
view on scratch
view on legacy ocular
BlockGardens
loading
This is actually possible, you just have a limit. Let's say the limit is 256, to simplify things. There must be one variable, called “tick”. If all 256 slots are full, it should look something like this.
0001011101101010101… and so on.
What we need is to be able to keep track of all of the digits at once. Your tick should be changing from 0 to 1 every 0.1 seconds, and there can be 256 clones to keep track of their individual tick. (I'd tell you how to use CloneID, but i'm assuming you're not a noob.)
They should wait 3 times, and check if all times are the same. They wait 0.1 seconds each time (obviously), so it should take 0.3 seconds to delete a player if they're inactive.
For example, if their recording is 000 or 111, that player is inactive and can be kicked out. But if it's 001 or 110 or 010 or such, that player can be ignored for now.
This is just a quick summary of how it works. Actually doing it would be considerably harder.
To measure the number of players, that's easy, just do length(allTicks).
0001011101101010101… and so on.
What we need is to be able to keep track of all of the digits at once. Your tick should be changing from 0 to 1 every 0.1 seconds, and there can be 256 clones to keep track of their individual tick. (I'd tell you how to use CloneID, but i'm assuming you're not a noob.)
They should wait 3 times, and check if all times are the same. They wait 0.1 seconds each time (obviously), so it should take 0.3 seconds to delete a player if they're inactive.
For example, if their recording is 000 or 111, that player is inactive and can be kicked out. But if it's 001 or 110 or 010 or such, that player can be ignored for now.
This is just a quick summary of how it works. Actually doing it would be considerably harder.
To measure the number of players, that's easy, just do length(allTicks).
Nov 30, 2020 17:35:34
how do you make a players online counter?
view on scratch
view on legacy ocular
DerpyHead0
loading
that acutally doesn't work, because online players set the ENTIRE variable. so if someone that has bad internet joins, they'll keep overwriting the cloud variable with old data (which means overwriting everyone's ticks) and stop the ticks from working properly. This is actually possible, you just have a limit. Let's say the limit is 256, to simplify things. There must be one variable, called “tick”. If all 256 slots are full, it should look something like this.
0001011101101010101… and so on.
What we need is to be able to keep track of all of the digits at once. Your tick should be changing from 0 to 1 every 0.1 seconds, and there can be 256 clones to keep track of their individual tick. (I'd tell you how to use CloneID, but i'm assuming you're not a noob.)
They should wait 3 times, and check if all times are the same. They wait 0.1 seconds each time (obviously), so it should take 0.3 seconds to delete a player if they're inactive.
For example, if their recording is 000 or 111, that player is inactive and can be kicked out. But if it's 001 or 110 or 010 or such, that player can be ignored for now.
This is just a quick summary of how it works. Actually doing it would be considerably harder.
To measure the number of players, that's easy, just do length(allTicks).
also, 256 clones just sitting in the background isn't a good idea, that would cause tons of unneccecary lag and leaves less room in the project for other clones.
Nov 30, 2020 17:38:35
how do you make a players online counter?
view on scratch
view on legacy ocular
BlockGardens
loading
Hm, I never thought about that. Maybe we can use Translate and forbid anyone with bad internet from joining? And make every clone handle 4 ticks rather than 1?that acutally doesn't work, because online players set the ENTIRE variable. so if someone that has bad internet joins, they'll keep overwriting the cloud variable with old data (which means overwriting everyone's ticks) and stop the ticks from working properly. This is actually possible, you just have a limit. Let's say the limit is 256, to simplify things. There must be one variable, called “tick”. If all 256 slots are full, it should look something like this.
0001011101101010101… and so on.
What we need is to be able to keep track of all of the digits at once. Your tick should be changing from 0 to 1 every 0.1 seconds, and there can be 256 clones to keep track of their individual tick. (I'd tell you how to use CloneID, but i'm assuming you're not a noob.)
They should wait 3 times, and check if all times are the same. They wait 0.1 seconds each time (obviously), so it should take 0.3 seconds to delete a player if they're inactive.
For example, if their recording is 000 or 111, that player is inactive and can be kicked out. But if it's 001 or 110 or 010 or such, that player can be ignored for now.
This is just a quick summary of how it works. Actually doing it would be considerably harder.
To measure the number of players, that's easy, just do length(allTicks).
also, 256 clones just sitting in the background isn't a good idea, that would cause tons of unneccecary lag and leaves less room in the project for other clones.
Nov 30, 2020 17:39:17
how do you make a players online counter?
view on scratch
view on legacy ocular
_THEBOSS_7
loading
guess its not as simple as i thought…. clones are no problem for me, lag sure, but i am not using clones.
Nov 30, 2020 17:55:09
how do you make a players online counter?
view on scratch
view on legacy ocular
BlockGardens
loading
Yeah.
Nov 30, 2020 18:02:35
how do you make a players online counter?
view on scratch
view on legacy ocular
DerpyHead0
loading
it would be almost impossible to check if someone is messing up other players ticks, and if this means preventing people from playing the game properly, it's a really bad idea. Maybe we can use Translate and forbid anyone with bad internet from joining?
lag can prevent a lot of people with worse computers from playing the game, and again, preventing people from playing the game properly is a terrible idea. guess its not as simple as i thought…. clones are no problem for me, lag sure, but i am not using clones.
what do you even need this online counter for? is it acutally important for the game, is the game multiplayer, or is it just something cool? because if it's not needed i don't think it's worth adding, if it's just some counter to try and show how popular the game is, there's lots of other things you can do, like a top score list, a counter for players that have beaten the game, etc.
Nov 30, 2020 18:20:09
how do you make a players online counter?
view on scratch
view on legacy ocular
_THEBOSS_7
loading
it's not a game, it's a reverse whitelisted chat. link; ( it broken rn ) https://scratch.mit.edu/projects/455826566/
Nov 30, 2020 18:24:52
how do you make a players online counter?
view on scratch
view on legacy ocular
DerpyHead0
loading
2 things:
1) this project is just a regular whitelist, you have whitelist and blacklist mixed up
2) online chats aren't allowed on scratch, even with the whitelist
1) this project is just a regular whitelist, you have whitelist and blacklist mixed up
2) online chats aren't allowed on scratch, even with the whitelist
Nov 30, 2020 18:27:23
how do you make a players online counter?
view on scratch
view on legacy ocular
_THEBOSS_7
loading
whitelists only stop certain words, this ONLY allows words in the list, so it is not technically an open chat.
( come to think of it you are prob. right, but this is not open chat, it's technically the same thing as looking at a ton of buttons and choosing what word to say, except u type )
( come to think of it you are prob. right, but this is not open chat, it's technically the same thing as looking at a ton of buttons and choosing what word to say, except u type )
Nov 30, 2020 18:33:22
how do you make a players online counter?
view on scratch
view on legacy ocular
DerpyHead0
loading
no, whitelists only stop certain words, this ONLY allows words in the list, so it is not technically an open chat.blacklists only stop certain words, and it's still an online chat. people can still put words together to insult people, give contact info, etc. it doesn't matter how you limit the words, until it gets to the point where it's not even a chat anymore.
the only thing i think is allowed is only being able to select from a list of possible messages, which then you can't really have any kind of conversation.
Nov 30, 2020 19:29:03
how do you make a players online counter?
view on scratch
view on legacy ocular
diggy5555
loading
um my game isn't working and i don't have much experience with online games game issue
Nov 30, 2020 19:31:05
how do you make a players online counter?
view on scratch
view on legacy ocular
_THEBOSS_7
loading
game issue1) make your own topic next time um my game isn't working and i don't have much experience with online games
2) can't help you, sorry.
Dec 1, 2020 14:46:19
how do you make a players online counter?
view on scratch
view on legacy ocular
BlockGardens
loading
Wait, what if we use a “temp” variable?it would be almost impossible to check if someone is messing up other players ticks, and if this means preventing people from playing the game properly, it's a really bad idea. Maybe we can use Translate and forbid anyone with bad internet from joining?lag can prevent a lot of people with worse computers from playing the game, and again, preventing people from playing the game properly is a terrible idea. guess its not as simple as i thought…. clones are no problem for me, lag sure, but i am not using clones.
what do you even need this online counter for? is it acutally important for the game, is the game multiplayer, or is it just something cool? because if it's not needed i don't think it's worth adding, if it's just some counter to try and show how popular the game is, there's lots of other things you can do, like a top score list, a counter for players that have beaten the game, etc.
Dec 1, 2020 15:04:25
how do you make a players online counter?
view on scratch
view on legacy ocular
_THEBOSS_7
loading
wdym?
Apr 7, 2022 22:07:08
how do you make a players online counter?
view on scratch
view on legacy ocular
coooolboy55
loading
its possible
variables
a cloud variable called max
a local variable called tcgf (times clicked green flag)
code
when green flag clicked
change max by 1
change tcgf by 1
if tcgf > 1 then
change max by -1
forever
reset timer
2nd code
when timer > 0
change max by -1
set tgcf to 0
variables
a cloud variable called max
a local variable called tcgf (times clicked green flag)
code
when green flag clicked
change max by 1
change tcgf by 1
if tcgf > 1 then
change max by -1
forever
reset timer
2nd code
when timer > 0
change max by -1
set tgcf to 0
Apr 7, 2022 22:49:36
how do you make a players online counter?
view on scratch
view on legacy ocular
IMAhomosapien
loading
when green flag clicked
change(☁ players)by (1)
Apr 7, 2022 22:57:44
how do you make a players online counter?
view on scratch
view on legacy ocular
coooolboy55
loading
oops the tcgf variable is not local its global
Apr 7, 2022 22:59:49
how do you make a players online counter?
view on scratch
view on legacy ocular
coooolboy55
loading
but it still works when its local
Apr 7, 2022 23:01:36
how do you make a players online counter?
view on scratch
view on legacy ocular
coooolboy55
loading
when green flag clicked
change(☁ players)by (1)
[/quote]
if we press the green flag more than one time it will glitch
also if you press the stop sign it wont remove anything
Apr 7, 2022 23:03:36
how do you make a players online counter?
view on scratch
view on legacy ocular
coooolboy55
loading
when green flag clicked
change(☁ players)by (1)
if we press the green flag more than one time it will glitch
also if you press the stop sign it wont remove anything
Mar 14, 2024 08:47:02
how do you make a players online counter?
view on scratch
view on legacy ocular
TeamNITE_gaming
loading
could you use the scratch blocks to re do that cde plz. I need code 2!
Mar 14, 2024 12:22:48
how do you make a players online counter?
view on scratch
view on legacy ocular
homewins
loading
The basic concept is set the PLAYERS variable to 0 and go through a loop, checking if each player is active. If so, you can change PLAYERS by 1.
There is probably a variable called “active” or something like that in each player clone that tells you if that player is active. If this is the case, just have a different sprite set PLAYERS to 0 and then add an
There is probably a variable called “active” or something like that in each player clone that tells you if that player is active. If this is the case, just have a different sprite set PLAYERS to 0 and then add an
if <[active] > [0]> then //assumes "active" variable is greater than 0 when the player is active
change [PLAYERS v] by (1)
end
//in a different sprite that runs its code before the "Cloud players" sprite:
set [PLAYERS v] to [0]
Mar 14, 2024 22:50:02
how do you make a players online counter?
view on scratch
view on legacy ocular
TeamNITE_gaming
loading
thx!
Mar 27, 2024 13:59:19
how do you make a players online counter?
view on scratch
view on legacy ocular
tigeralaunch
loading
maybe we can use the “current second” operator and always refresh the player count every second?
Mar 31, 2024 21:19:58
how do you make a players online counter?
view on scratch
view on legacy ocular
Calvin9901
loading
when I start as a clone
delete this clone
delete this clone