For those of you who would like to play around with linking two Scratch projects over a network, but don't want to mess around with Python, this Adobe AIR program might be of interest:
http://scratchconnections.wik.is/User:Chalkmarrow/Snyff
Basically, when two computers are hooked up, broadcasts from one computer are also seen by the other, and global variables from one computer show up as sensor values in the other. There are also some special features to make things easier to design multi-player projects.
It is based on archmage's idea of using Flash as the go-between, and is written in Adobe Flex (MXML + Actionscript 3). It runs as an executable file on any platform, and is simple to use.
The source code is included on the site (or you can just right click the application).
Once you have two computers hooked up, Snyff operates in accordance with only four simple rules:
1. Every global variable (not list or local variable) you change or create in one computer appears as a sensor value (blue blocks) in the other computer.
2. Every broadcast in one computer gets sent as a broadcast to the other computer, except:
3. Every broadcast that starts with "@" is _not_ sent to the other computer, and
4. Every broadcast that starts with ">" is changed to start with "<" and _then_ sent to the other computer.
That's it.
Last edited by chalkmarrow (2009-04-03 16:14:13)
Offline
This looks amazing! Oh, the possibilities...
The documentation looks great, very complete. There are a couple of odd coding tags that are hanging out in it (when viewed with IE7 anyway).
Great job!
Offline
abeair wrote:
Cool! My AIR needs an update, though. It wouldn't install, saying "Adobe AIR needs to be updated. Installing the update failed."
Yeah, you need AIR 1.5, which I confirmed works with Snyff on Ubuntu 8.10, WinXP, and MacOSX.
Offline
chalkmarrow wrote:
abeair wrote:
Cool! My AIR needs an update, though. It wouldn't install, saying "Adobe AIR needs to be updated. Installing the update failed."
Yeah, you need AIR 1.5, which I confirmed works with Snyff on Ubuntu 8.10, WinXP, and MacOSX.
Thanks.
Offline
Jens wrote:
I *love* this, chalkmarrow! Especially the brilliant idea to use special characters to control message addressees, and the "snyffsez" lolcat-ish system messages. You're a genius!
Thanks! It's actually a lot of fun. I was playing a simple two-person Doodle game with someone in another room and we couldn't stop laughing.
Re the special characters, I really tried to make the program as simple and vanilla as possible, without any messy additions, but it became apparent early on that there are certain difficulties inherent in building projects where every broadcast is seen everywhere.
To make it easier, I had to address two broadcast-namespace issues. The first was that you need to have a project-specific namespace for your own computer (thus the "@" prefix), and the second was that you needed a project-specific namespace for your friend's computer (thus ">"). The second one gives you a way to break the "symmetry" of broadcasting.
The other major problem is that you can't create sensor-variables during design time (V1.5, anyone?). You would have to go through the trouble of connecting to another computer just to create the sensor variables to stick in your scripts. That's why I made the design helper part.
Offline
I agree that routing messages to specific targets looks like the way to go. I've experimented with an expanded broadcasting system myself, but only within a single Scratch project, in which each object can either broadcast messages to all, so a specific other object, or - as subroutines - to itself. But I didn't manage to apply that to networked Scratch sessions. Usually I'm not a big fan of reserved special chars in messages, however, I love your idea because of its simplicity and because it works :-) - and also because it's way cool!
Offline
Jens wrote:
I agree that routing messages to specific targets looks like the way to go. I've experimented with an expanded broadcasting system myself, but only within a single Scratch project, in which each object can either broadcast messages to all, so a specific other object, or - as subroutines - to itself. But I didn't manage to apply that to networked Scratch sessions. Usually I'm not a big fan of reserved special chars in messages, however, I love your idea because of its simplicity and because it works :-) - and also because it's way cool!
Nice. I like the pinpointed broadcast concept.
And yeah, I was pretty hesitant to use the special characters also. At first, I used special commands, but that got a bit cumbersome and easy to mess up. As I may have mentioned, I designed it with my 9-year-old watching me and telling me what made sense to him. The idea that putting a @ or > as a first character changes the way a broadcast bounces around is very intuitive, but when I used command syntax like "snyff selfbroadcast hello", not so much. I think this has to do with kids' comfort with the idea of prefixes in language.
Last edited by chalkmarrow (2009-04-01 17:05:42)
Offline
My question is, do you have to trust the other user enough to make a connection to them and 2 what if I don't want to give out my IP?
Offline
Well the host computer doesn't need to give their IP but the remote computer does.
I wouldn't worry about IP sharing, I know a few games that do this sort of thing.
Offline
archmage wrote:
Well the host computer doesn't need to give their IP but the remote computer does.
I wouldn't worry about IP sharing, I know a few games that do this sort of thing.
Yeah. You're trading your IP address with hundreds of computers each day, actually.
I should warn you that it is difficult to set up a socket connection between two home computers via the Internet, because there are typically two or more firewalls in the way, and configuring them is a real pain. I made the program primarily to play games across a home network.
Also, remember, your IP address as it appears within your network is different from how it appears from outside the network (because of your cable modem, router, gateway, whatever else).
So, for example, when I go to whatsmyip.org on this computer, it tells me that my IP address is:
68.108.193.54
but when I ask my computer (via a Windows console), it says my IP address is:
192.168.0.8
Offline
So if you are behind a router this is how you find your IP on a PC running windows.
1. Click start
2.Click all programs
3. Click accessories
4. Click Command Prompt
5. Type ipconfig into the prompt
Now this you give you a bunch of info about your connection. Just look for something that says IP address and the number beside it is your IP address.
Offline
archmage wrote:
So if you are behind a router this is how you find your IP on a PC running windows.
1. Click start
2.Click all programs
3. Click accessories
4. Click Command Prompt
5. Type ipconfig into the prompt
Now this you give you a bunch of info about your connection. Just look for something that says IP address and the number beside it is your IP address.
Exactly. Plus on a mac you type "netstat", and on linux you type "ifconfig".
Offline
A good guide to the sort of things you need to do to allow socket connections through a firewall is in Agnes Chang's guide to her networked pong game:
http://scratchconnections.wik.is/Projects/Two-player_Network_Pong
Offline
*bows down to chalkmarrow*
Offline
archmage wrote:
So if you are behind a router this is how you find your IP on a PC running windows.
1. Click start
2.Click all programs
3. Click accessories
4. Click Command Prompt
5. Type ipconfig into the prompt
Now this you give you a bunch of info about your connection. Just look for something that says IP address and the number beside it is your IP address.
Or you can:
Click start
then click run
type in cmd
press enter
type in ipconfig
look for the ip. there ya go
Offline
KingOfGames wrote:
Or you can:
Click start
then click run
type in cmd
press enter
type in ipconfig
look for the ip. there ya go
Vista doesn't have a Run button...you have to find the Command Prompt application
Offline
What is the feasiblity of using this for projects involving more than two computers? I notice that there is an effort afoot to try and make something larger over here
http://scratch.mit.edu/forums/viewtopic.php?pid=105328#p105328
The last time I looked into this, I really didn't see how the sockets could be made to work with more than one computer at a time so it seemed like you would have to continually be opening and closing sockets.
Offline
Paddle2See wrote:
What is the feasiblity of using this for projects involving more than two computers? I notice that there is an effort afoot to try and make something larger over here
http://scratch.mit.edu/forums/viewtopic.php?pid=105328#p105328
Thanks. I hadn't seen that link.
The last time I looked into this, I really didn't see how the sockets could be made to work with more than one computer at a time so it seemed like you would have to continually be opening and closing sockets.
I am planning on trying something on a small scale in my home network connecting four or five computers. What you do is, each computer has its own copy of Snyff, with one connection made to Scratch at localhost, and the other connection made to a base socket server running on a base computer (which I haven't even scratched the surface of). This is a long term project, though, as the optimal logic for communication between computers is still not clear to me (though I made Snyff as general as possible so that I wouldn't have to worry about it early on). I suspect the actual real programmers out there will probably figure this out way before I do
Offline
That is excataly what I was thinking could be done as well.
I just wonder how many connections it takes to crash the base sever.
Offline
I am assuming we are dealing with TCP sockets, where I believe the server creates one socket for each client, but the sockets share the same local socket address. Like I said, though, I haven't really looked into it yet.
Offline
You know, there's also an experimental "hidden" feature in the public Scratch Source Code which you can unlock without having to get much into Smalltalk-programming at all, and which will let you connect any number of Scratch sessions via TCP to do your MMO's without any middleware involved: http://scratch.mit.edu/forums/viewtopic.php?pid=96799#p96799
Offline
Jens wrote:
You know, there's also an experimental "hidden" feature in the public Scratch Source Code which you can unlock without having to get much into Smalltalk-programming at all, and which will let you connect any number of Scratch sessions via TCP to do your MMO's without any middleware involved: http://scratch.mit.edu/forums/viewtopic.php?pid=96799#p96799
That looks like a cool option, which I haven't looked into yet. So is the result the same? Every broadcast/global variable gets shared? The only problem I would forsee is that superglobal broadcasts, in practice, can be confusing. On the other hand, it sure simplifies the task of making a server. I'll have to try that out.
Offline