This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-11-13 17:45:45

MisterDuck
Scratcher
Registered: 2012-05-15
Posts: 8

Scratch 2.0 Check if user leaves session

I suggest adding a conditional to scratch 2.0 that checks if the user has closed the window or the project frame has lost focus. This is helpful if you have a multiplayer room that says how many people are there, and if the person leaves, then you can subtract 1 from that variable.

if <session leaved>
  change [PeopleInRoom v] by [-1]

Last edited by MisterDuck (2012-11-13 17:46:37)

Offline

 

#2 2012-11-13 17:47:26

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Scratch 2.0 Check if user leaves session

I'd say this should be a hat block, but it's a nice idea.

However, when the user leaves, it closes Scratch, meaning it can't run anymore blocks, so I'm not sure how good it would be.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#3 2012-11-14 12:56:15

iTweak0r
Scratcher
Registered: 2011-07-30
Posts: 100+

Re: Scratch 2.0 Check if user leaves session

Maybe it runs 1 more block before it closes like the slide animation on GitHub

grr 60 seconds rule


Make it in Scratch! because it's cooler when it's made in scratch
http://i.imgur.com/D4iqPHR.png

Offline

 

#4 2012-11-14 14:26:24

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Scratch 2.0 Check if user leaves session

you can workaround it

Offline

 

#5 2012-11-14 21:42:26

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: Scratch 2.0 Check if user leaves session

roijac wrote:

you can workaround it

exactly what i was thinking  tongue
Come 2.0, you could make it so that if a person is connected, then they keep sending packets, it guess you could call them?  Then, if the packets are not being sent, then they are removed from the list.  I'd have to take some time to think of the actual code, though, because there is no server side scripting

EDIT: just came up with some experimental code:

when gf clicked
forever
if <<(☁ refresh) = [1] > and <not<[☁online v] contains (user id)>>>
add (user id) to [☁online v]//a cloud list
end
when I receive [send_packets v]
set [☁refresh v] to [0]
delete (all v) of [☁online v]
set [☁refresh v] to [1]
wait (☁refresh rate) secs //should be determined server side
broadcast [send_packets v]

The cloud list "online" would contain a list of all user id's logged on
Once a user closes scratch, it will stop sending these "packets", and it will be detected by all the other clients acting for the server
And if no one else is on, then, once someone logs on, it will be detected

also, simply broadcast send_packets to start it
I'll soon update this to include a way to switch it off, which is actually simple

Note that this wouldn't work if, for example, you wanted to show a shutdown program if a window is closed.  That would be rather hard to do, and some browsers might block it

Last edited by SJRCS_011 (2012-11-14 22:04:43)


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

Board footer