Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Detecting If Player Quit On Online Multiplayer
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
How can I detect if a player quit the game and either hit the stop button or goes to a different website? I also would like it to change/set some variables by -1. Help will be appreciated.
- peppermintpatty5
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
Maybe you could have your project detect if a key has been pressed in the last 30 or so seconds:

So something along these lines. If your game uses the mouse, then I could probably think up a script for that.

- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
Thanks for the idea Maybe you could have your project detect if a key has been pressed in the last 30 or so seconds:So something along these lines. If your game uses the mouse, then I could probably think up a script for that.

- peppermintpatty5
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
whoops, double post…
Last edited by peppermintpatty5 (Aug. 17, 2015 01:08:00)
- peppermintpatty5
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
Hmm, there is a way to detect when the stop sign is clicked.
It works because this block will run even when the project has stopped:

Btw, you won't be able to use the timer anywhere else in your project if you implement this.
There's a workaround to not having the timer though…
It works because this block will run even when the project has stopped:
Hope this helps!

Btw, you won't be able to use the timer anywhere else in your project if you implement this.

There's a workaround to not having the timer though…

Last edited by peppermintpatty5 (Aug. 17, 2015 01:06:30)
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
when the stop sign is clicked.Thanks so much Hmm, there is a way to detect
It works because this block will run even when the project has stopped:Hope this helps!
Btw, you won't be able to use the timer anywhere else in your project if you implement this.
There's a workaround to not having the timer though…


I'll look it up to see if there's any other methods. If there isn't, I'll just use this method and use a workaround for the timer.
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
Ok, I looked it up, and everything I see is using the timer. Kind of disappointingwhen the stop sign is clicked.Thanks so much Hmm, there is a way to detect
It works because this block will run even when the project has stopped:Hope this helps!
Btw, you won't be able to use the timer anywhere else in your project if you implement this.
There's a workaround to not having the timer though…! But that's kind of disappointing that you can't use the timer anywhere else in your project
I'll look it up to see if there's any other methods. If there isn't, I'll just use this method and use a workaround for the timer.

- deck26
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
What you really need is a cloud variable that is being changed repeatedly (eg once a second) by the player. Other players can see that the variable is changing by saving a copy of the variable and waiting a few seconds before seeing if it has changed. This works for the player pressing the stop button or just closing the web page which is not the case for anything using the timer and the stop button. You need something like this for managing player slots in a multiplayer.
My demo combines the x,y position, costume number and this player-slot-reservation in a single cloud variable per player. https://scratch.mit.edu/projects/63501310/
My demo combines the x,y position, costume number and this player-slot-reservation in a single cloud variable per player. https://scratch.mit.edu/projects/63501310/
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
Exactly What you really need is a cloud variable that is being changed repeatedly (eg once a second) by the player. Other players can see that the variable is changing by saving a copy of the variable and waiting a few seconds before seeing if it has changed. This works for the player pressing the stop button or just closing the web page which is not the case for anything using the timer and the stop button. You need something like this for managing player slots in a multiplayer.
My demo combines the x,y position, costume number and this player-slot-reservation in a single cloud variable per player. https://scratch.mit.edu/projects/63501310/

Last edited by julianandwill (Aug. 17, 2015 20:07:48)
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
But, do scratch projects stop when you leave the website? I'm just wondering. I'm pretty sure it's yes because they reset.Exactly What you really need is a cloud variable that is being changed repeatedly (eg once a second) by the player. Other players can see that the variable is changing by saving a copy of the variable and waiting a few seconds before seeing if it has changed. This works for the player pressing the stop button or just closing the web page which is not the case for anything using the timer and the stop button. You need something like this for managing player slots in a multiplayer.
My demo combines the x,y position, costume number and this player-slot-reservation in a single cloud variable per player. https://scratch.mit.edu/projects/63501310/except I already have the player slots set up.
- liam48D
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
They “reset” because when you leave a project, Scratch doesn't save the project's data to the server. When you re-open the page Scratch loads what the project was last time it was saved.But, do scratch projects stop when you leave the website? I'm just wondering. I'm pretty sure it's yes because they reset.Exactly What you really need is a cloud variable that is being changed repeatedly (eg once a second) by the player. Other players can see that the variable is changing by saving a copy of the variable and waiting a few seconds before seeing if it has changed. This works for the player pressing the stop button or just closing the web page which is not the case for anything using the timer and the stop button. You need something like this for managing player slots in a multiplayer.
My demo combines the x,y position, costume number and this player-slot-reservation in a single cloud variable per player. https://scratch.mit.edu/projects/63501310/except I already have the player slots set up.
- gtoal
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
Thanks so much! But that's kind of disappointing that you can't use the timer anywhere else in your project
I'll look it up to see if there's any other methods. If there isn't, I'll just use this method and use a workaround for the timer.
Yes you can :-)
https://scratch.mit.edu/projects/58656772/
- gtoal
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
Oh btw, do Scratch projects stop if you leave the website?
No, unfortunately. I'm working on trying to create a reliable mechanism to do that (http://scratch.mit.edu/projects/41470142/) but to be honest I don't hold out a lot of hope that I will ever get it to work…
G
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
I know. I said “I will use a workaround for the timer”.Thanks so much! But that's kind of disappointing that you can't use the timer anywhere else in your project
I'll look it up to see if there's any other methods. If there isn't, I'll just use this method and use a workaround for the timer.
Yes you can :-)
https://scratch.mit.edu/projects/58656772/
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
No, I mean when you leave the website, does the project act as if the stop sign is clicked?They “reset” because when you leave a project, Scratch doesn't save the project's data to the server. When you re-open the page Scratch loads what the project was last time it was saved.But, do scratch projects stop when you leave the website? I'm just wondering. I'm pretty sure it's yes because they reset.Exactly What you really need is a cloud variable that is being changed repeatedly (eg once a second) by the player. Other players can see that the variable is changing by saving a copy of the variable and waiting a few seconds before seeing if it has changed. This works for the player pressing the stop button or just closing the web page which is not the case for anything using the timer and the stop button. You need something like this for managing player slots in a multiplayer.
My demo combines the x,y position, costume number and this player-slot-reservation in a single cloud variable per player. https://scratch.mit.edu/projects/63501310/except I already have the player slots set up.
- deck26
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
No, I mean when you leave the website, does the project act as if the stop sign is clicked?
If, for example, you close the browser the project cannot detect that - even with the timer/stop button trick. I'd guess the same would apply if you told the browser to go to another page.
So leaving the website cannot be detected in the same way as the stop sign being clicked.
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
Hmm… Is there any workaround for this?No, I mean when you leave the website, does the project act as if the stop sign is clicked?
If, for example, you close the browser the project cannot detect that - even with the timer/stop button trick. I'd guess the same would apply if you told the browser to go to another page.
So leaving the website cannot be detected in the same way as the stop sign being clicked.
- deck26
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
That's why people use the method of a variable being constantly updated - it detects the stop flag or moving away from the page/closing browser since the variable no longer gets updated. If you're concerned about cloud variables detecting the change that's the answer - the instance of the project can't possibly detect that it's not running if the browser window has disappeared under its feet!
- julianandwill
-
500+ posts
Detecting If Player Quit On Online Multiplayer
Hmm… make a project that explains what happens. That's why people use the method of a variable being constantly updated - it detects the stop flag or moving away from the page/closing browser since the variable no longer gets updated. If you're concerned about cloud variables detecting the change that's the answer - the instance of the project can't possibly detect that it's not running if the browser window has disappeared under its feet!
- deck26
-
1000+ posts
Detecting If Player Quit On Online Multiplayer
It's actually quite simple.
When an instance of the project is running a cloud variable for that player is constantly being changed. Another instance of the project can see the cloud variable and easily see that it is changing by
- copy cloud variable to a local variable
- wait a few seconds
- check the cloud variable against the local variable
If the cloud variable has changed some instance of the project is changing it. If it is unchanged there is no instance of the project managing that variable (indicating a free player slot).
Clicking the stop sign, closing the browser or linking that browser tab to another page will all stop the local instance of the project from updating the variable so other instances will see the player slot as no longer busy.
(An instance of the project just means a copy running somewhere. If I run your project my instance will book a slot and if you run it your instance will book another.)
When an instance of the project is running a cloud variable for that player is constantly being changed. Another instance of the project can see the cloud variable and easily see that it is changing by
- copy cloud variable to a local variable
- wait a few seconds
- check the cloud variable against the local variable
If the cloud variable has changed some instance of the project is changing it. If it is unchanged there is no instance of the project managing that variable (indicating a free player slot).
Clicking the stop sign, closing the browser or linking that browser tab to another page will all stop the local instance of the project from updating the variable so other instances will see the player slot as no longer busy.
(An instance of the project just means a copy running somewhere. If I run your project my instance will book a slot and if you run it your instance will book another.)
- Discussion Forums
- » Help with Scripts
-
» Detecting If Player Quit On Online Multiplayer