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

#26 2009-04-04 10:00:38

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Doesn't MMO stand for Massivly Multiplayer Online? If it does we should start calling the game MMOG for Massivly Multiplayer Online Game. XD

Last edited by Magnie (2009-04-04 10:01:35)

Offline

 

#27 2009-04-06 10:58:50

abeair
Scratcher
Registered: 2008-07-19
Posts: 100+

Re: Snyff: Simplified Scratch Networking

Magnie wrote:

Doesn't MMO stand for Massivly Multiplayer Online? If it does we should start calling the game MMOG for Massivly Multiplayer Online Game. XD

True! ROFL!!!!


http://dragcave.net/image/NPtA.gif
http://www.danasoft.com/sig/ObamaLovesMacs.jpg

Offline

 

#28 2009-04-06 14:06:08

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Someone make it so I can get Adobe AIR!! Like make it so I can choose where to install it. Please!  smile

EDIT: I looked into Adobe AIR (I still can't install it) but it says you can have online application on your computer. I thought could you make it so Snyff can be an online application? Then you don''t need to download anything but the game/scratch project.

Last edited by Magnie (2009-04-06 14:41:15)

Offline

 

#29 2009-04-06 16:00:52

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Magnie wrote:

Someone make it so I can get Adobe AIR!! Like make it so I can choose where to install it. Please!  smile

EDIT: I looked into Adobe AIR (I still can't install it) but it says you can have online application on your computer. I thought could you make it so Snyff can be an online application? Then you don''t need to download anything but the game/scratch project.

Thats not possible. Letting an online program like that would pose a security risk. At least that was the case with my flash program. If I ever do finish it it will be the same as the snyff except in an exe format with no install.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#30 2009-04-06 19:47:26

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Well it like said that "Keep your favorite browser games on your computer"....

Offline

 

#31 2009-04-07 13:08:59

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: Snyff: Simplified Scratch Networking

Magnie: I uploaded a zipped windows version (snyff.zip) here:

http://scratchconnections.wik.is/User:Chalkmarrow/Snyff

Last edited by chalkmarrow (2009-04-07 13:09:28)

Offline

 

#32 2009-04-07 16:42:34

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you!

EDIT: It requires AIR....  sad

Last edited by Magnie (2009-04-07 16:44:54)

Offline

 

#33 2009-04-07 17:17:02

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: Snyff: Simplified Scratch Networking

Magnie wrote:

Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you!

EDIT: It requires AIR....  sad

Right. The zipped file just lets you bypass install of snyff using AIR. You're still going to have to run it on AIR. Even if there is a portable AIR executable, I could not distribute it on a website without a distribution agreement. Your best bet is still just to ask your administrator to download it.

The other alternative is for someone to convert it to a .swf file that runs in a browser (it was created in Adobe Flex using the AIR settings, so it includes components that are AIR-specific).

Offline

 

#34 2009-04-08 09:54:35

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Admins = My Parents  smile
My Mom says I have to talk to my Dad. So I guess I'll try that.  smile
But please keep trying thank you.  smile

This may be off topic. My Dad says that Flash is not in his interests so he won't install that so I might not be able to get AIR.  sad
Could you explain the second solution? Thanks!  smile

Offline

 

#35 2009-04-08 13:01:01

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Just say its like an add on for scratch. If he lets you install scratch then air should be fine too.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#36 2009-04-13 08:58:13

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Actually I put Scratch on my desktop.  smile

Offline

 

#37 2009-04-13 13:55:43

dingdong
Scratcher
Registered: 2007-08-09
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

omg! XD yesterday the link was broken, but today it works!!! my first thing will be to make a chatroom with this then from there add a game to the chatroom, hopefully I can make some intersting stuff with this

edit:
XD I'm controlling the scratch cat with another program!!! this is great!

Last edited by dingdong (2009-04-13 14:02:49)


http://img851.imageshack.us/img851/2829/superanbanner.png
click the image for my music

Offline

 

#38 2009-04-13 23:21:29

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Sounds cool, but why is this on Sensor Boards?  neutral


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#39 2009-04-14 05:47:45

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

technoguyx wrote:

Sounds cool, but why is this on Sensor Boards?  neutral

Because it uses similar techniques as the Sensor Board to communicate with Scratch.  And to turn on Remote Sensing (which it uses) you have to right-click on a Sensor Board block and pick the Remote Sensing option. 

But maybe you are right, maybe this would be more at home in the Advanced Topics area.  What do you folks think?


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#40 2009-04-14 09:20:54

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Yea. I was wondering the same thing. I think it should be in Advanced Topics.  smile

Offline

 

#41 2009-04-14 12:11:32

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: Snyff: Simplified Scratch Networking

Yeah. I had the same thought, but it seems to fit within the description of the forum, viz.: "Topics relating to Scratch Boards, PicoBoards, and Scratch sensing and responding to things happening in the world around it." But Perhaps Advanced Features would be better.

Offline

 

#42 2009-04-14 19:33:50

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

I agree that Snyff is probably the most advanced Scratch-related topic I have seen in a long time. How about renaming the "Sensor Boards" forum section into something like "External Devices"? That way it would be open to discussions about all kinds of peripherals interfacing with Scratch, not just the - awsome - Picoboard.


Jens Mönig

Offline

 

#43 2009-04-15 03:28:31

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

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

I tried that option some time ago, and it works perfectly and it's so fun!

I'm quite tired of Scratch dozens of hidden things behind Shift-Clicks, Control, Right-click-on-blocks-in-the-library and seemingly even switching a variable to true in the source code... OK if the feature is not working yet but this one certainly is.The shift click is taken out in 1.4 - good job  big_smile . When really lots of people need a feature - like the project summmary or the single stepping speed - it would be so cool to just have those options in a menu...

Joren


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#44 2009-04-27 16:45:46

dsdude10
Scratcher
Registered: 2007-09-22
Posts: 500+

Re: Snyff: Simplified Scratch Networking

is it possible to make games that support more than two players using snyff?

Offline

 

#45 2009-05-22 23:22:56

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

dsdude10 wrote:

is it possible to make games that support more than two players using snyff?

I believe that was the point of Snyff.  big_smile

Offline

 

#46 2009-06-08 14:26:31

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

Hey Chalkmarrow-
I've done a couple of tests with Snyff and 1.4 and I can't seem to get either computer to recognize sensor-updates so neither one can read the others' variables. Broadcasts work fine, though. Everything works great when I use the same setup with 1.3. Have you encountered the same problem?


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#47 2009-06-08 14:50:08

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

I am having the same issues as fullmoon


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#48 2009-06-08 15:49:36

fruit
Scratcher
Registered: 2009-04-24
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

same as archmage.


@savi3000 | hcsmp.com

Offline

 

#49 2009-06-08 16:22:19

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

I got 1.4 to receive sensor-updates with the following AS3 class:

Code:

package{
    //Import everything we need to work with flash.net.Socket and handle its events
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
    import flash.utils.ByteArray;
    import flash.net.Socket;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    public dynamic class ScratchSocket {

        //Reserve space for socket, but don't declare it
        private var socket:Socket;
        public function ScratchSocket() {
            //Declare socket
            socket=new Socket  ;
            connect();

        }
        private function connect():void {
            //Connect with Scratch on localhost, which responds to port 42001
            socket.connect("localhost",42001);
            socket.addEventListener(Event.CONNECT,socketConnect);
            socket.addEventListener(Event.UNLOAD,socketConnect);
            socket.addEventListener(Event.CLOSE,socketConnect);
            socket.addEventListener(IOErrorEvent.IO_ERROR,socketConnect);
            socket.addEventListener(ProgressEvent.SOCKET_DATA,dataIn);
        }
        public function update(sensor:String,value:String):void {
            //Function to send a sensor update to Scratch
            sendScratchMessage("sensor-update "+sensor+" "+value);
        }
        //Function to send a broadcast to Scratch
        public function broadcast(broadcast:String):void {
            trace("ScratchSocket.broadcast");
            sendScratchMessage('broadcast "'+broadcast+'"');
        }
        private function sendScratchMessage(sendData:String):void {
            //The Scratch Connections protocol requires every message sent to Scratch to
            //be preceded by four bytes indicating the message length
            var bytes:ByteArray=new ByteArray  ;
            //Here are three '0' bytes
            bytes[0]=0;
            bytes[1]=0;
            bytes[2]=0;
            //Here's the actual message length
            bytes[3]=sendData.length;
            //Now we write the preceder plus the actual message to the socket
            for (var i:Number=0; i<4; i++) {
                socket.writeByte(bytes[i]);
            }
            //Here comes the airplane!
            socket.writeMultiByte(sendData,"us-ascii");
            socket.flush();
        }
        private function socketConnect(Event):void {
            //Handle connection events linked in constructor
            switch (Event.type) {
                case 'connect' :
                    trace("connection successful");
                    update("sc.io.connectionReady","true");
                    break;
                case 'close' :
                    trace("connection failed");
                    update("sc.io.connectionReady","false");
                    connect();

                    break;
                case 'ioError' :
                    trace("connection failed through IOError");
                    update("sc.io.connectionReady","false");
                    break;
                case 'unload' :
                    update("sc.io.connectionReady","false");
                    break;

            }
        }
        private function dataIn(event:ProgressEvent):void {
            trace("ScratchSocket.dataIn");
            //Create an empty string
            var inString:String="";
            while (socket.bytesAvailable) {
                //Read the next part of the socket data into inString
                inString+=socket.readUTF();
            }
            //Send inString off to class SCparse for evaluation
            evaluate(inString);
        }
        // Parse the data received from Scratch
        private function evaluate(input:String) {
            trace("ScratchSocket.evaluate("+input+")");
            // Look for broadcast from Scratch
            // Matches any string starting with 'broadcast ' followed by a string of non-return characters in "quotes"
            var pattern1:RegExp=/broadcast\s\"(.*)"/;
            var result:Object=pattern1.exec(input);
            if (result!=null) {
                trace('Scratch broadcasted:'+result[1]);
                if (result[1].charAt(0)=="!") {
                    interpret(result[1].slice(1,result[1].length));
                }
            }
            // Look for sensor-update from Scratch
            // Matches any sensor-update string Scratch sends
            var pattern2:RegExp=/sensor-update\s\"Scratch-(.*)\"\s\"(.*)\"/;
            result=pattern2.exec(input);
            if (result!=null) {
                trace('Scratch changed variable '+result[1]+' to '+result[2]);
                //If the variable changed is 'sc.io.command' then interpret it.
                if (result[1]=="sc.io.command") {
                    interpret(result[2]);
                }
            }
        }
        private function interpret(input:String):void {
            trace("ScatchSocket.interpret("+input+")");
            var command:Array=input.split(" :: ");
            trace(command);
            var returnVal="";
            //If the command returns to an invalid sensor then return to the default sensor, 'sc.io.defaultReturn'.
            if (command[2].slice(0,6)!="sc.io.") {
                command[2]="sc.io.defaultReturn";
            }
            //Find out what the command wants
            switch (command[0]) {
                case "getURL" :
                    trace("sc.getURL");
                    navigateToURL(new URLRequest(command[1]));
                    returnVal="success";
                    update(command[2],returnVal);
                    break;
                case "nospace" :
                    trace("sc.concat");
                    var a:Array=command[1].split(" ");
                    for (var i=0; i<a.length; i++) {
                        if (a[i]=="") {
                            a[i]=" ";
                        }
                    }
                    break;
                case "charcode" :
                    trace("sc.charcode");
                    update(command[2],command[1].charCodeAt(0));
                    break;
                case "store" : 
                    //update(command[0],ScratchStorage.store(command[1]))
                    break;
            }


        }

    }
}

If you're interested in replicating this, you must instantiate a new ScratchSocket and call its update method:

Code:

var s:ScratchSocket=new ScratchSocket();
s.update(variableName,value)

Last edited by fullmoon (2010-10-31 01:25:24)


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#50 2009-06-08 16:39:48

fruit
Scratcher
Registered: 2009-04-24
Posts: 1000+

Re: Snyff: Simplified Scratch Networking

fullmoon wrote:

I got 1.4 to receive sensor-updates with the following AS3 class:

Code:

package{
    //Import everything we need to work with flash.net.Socket and handle its events
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
    import flash.utils.ByteArray;
    import flash.net.Socket;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    public dynamic class ScratchSocket {

        //Reserve space for socket, but don't declare it
        private var socket:Socket;
        public function ScratchSocket() {
            //Declare socket
            socket=new Socket  ;
            connect();

        }
        private function connect():void {
            //Connect with Scratch on localhost, which responds to port 42001
            socket.connect("localhost",42001);
            socket.addEventListener(Event.CONNECT,socketConnect);
            socket.addEventListener(Event.UNLOAD,socketConnect);
            socket.addEventListener(Event.CLOSE,socketConnect);
            socket.addEventListener(IOErrorEvent.IO_ERROR,socketConnect);
            socket.addEventListener(ProgressEvent.SOCKET_DATA,dataIn);
        }
        public function update(sensor:String,value:String):void {
            //Function to send a sensor update to Scratch
            sendScratchMessage("sensor-update "+sensor+" "+value);
        }
        //Function to send a broadcast to Scratch
        public function broadcast(broadcast:String):void {
            trace("ScratchSocket.broadcast");
            sendScratchMessage('broadcast "'+broadcast+'"');
        }
        private function sendScratchMessage(sendData:String):void {
            //The Scratch Connections protocol requires every message sent to Scratch to
            //be preceded by four bytes indicating the message length
            var bytes:ByteArray=new ByteArray  ;
            //Here are three '0' bytes
            bytes[0]=0;
            bytes[1]=0;
            bytes[2]=0;
            //Here's the actual message length
            bytes[3]=sendData.length;
            //Now we write the preceder plus the actual message to the socket
            for (var i:Number=0; i<4; i++) {
                socket.writeByte(bytes[i]);
            }
            //Here comes the airplane!
            socket.writeMultiByte(sendData,"us-ascii");
            socket.flush();
        }
        private function socketConnect(Event):void {
            //Handle connection events linked in constructor
            switch (Event.type) {
                case 'connect' :
                    trace("connection successful");
                    update("sc.io.connectionReady","true");
                    break;
                case 'close' :
                    trace("connection failed");
                    update("sc.io.connectionReady","false");
                    connect();

                    break;
                case 'ioError' :
                    trace("connection failed through IOError");
                    update("sc.io.connectionReady","false");
                    break;
                case 'unload' :
                    update("sc.io.connectionReady","false");
                    break;

            }
        }
        private function dataIn(event:ProgressEvent):void {
            trace("ScratchSocket.dataIn");
            //Create an empty string
            var inString:String="";
            while (socket.bytesAvailable) {
                //Read the next part of the socket data into inString
                inString+=socket.readUTF();
            }
            //Send inString off to class SCparse for evaluation
            evaluate(inString);
        }
        // Parse the data received from Scratch
        private function evaluate(input:String) {
            trace("ScratchSocket.evaluate("+input+")");
            // Look for broadcast from Scratch
            // Matches any string starting with 'broadcast ' followed by a string of non-return characters in "quotes"
            var pattern1:RegExp=/broadcast\s\"(.*)"/;
            var result:Object=pattern1.exec(input);
            if (result!=null) {
                trace('Scratch broadcasted:'+result[1]);
                if (result[1].charAt(0)=="!") {
                    interpret(result[1].slice(1,result[1].length));
                }
            }
            // Look for sensor-update from Scratch
            // Matches any sensor-update string Scratch sends
            var pattern2:RegExp=/sensor-update\s\"Scratch-(.*)\"\s\"(.*)\"/;
            result=pattern2.exec(input);
            if (result!=null) {
                trace('Scratch changed variable '+result[1]+' to '+result[2]);
                //If the variable changed is 'sc.io.command' then interpret it.
                if (result[1]=="sc.io.command") {
                    interpret(result[2]);
                }
            }
        }
        private function interpret(input:String):void {
            trace("ScatchSocket.interpret("+input+")");
            var command:Array=input.split(" :: ");
            trace(command);
            var returnVal="";
            //If the command returns to an invalid sensor then return to the default sensor, 'sc.io.defaultReturn'.
            if (command[2].slice(0,6)!="sc.io.") {
                command[2]="sc.io.defaultReturn";
            }
            //Find out what the command wants
            switch (command[0]) {
                case "getURL" :
                    trace("sc.getURL");
                    navigateToURL(new URLRequest(command[1]));
                    returnVal="success";
                    update(command[2],returnVal);
                    break;
                case "nospace" :
                    trace("sc.concat");
                    var a:Array=command[1].split(" ");
                    for (var i=0; i<a.length; i++) {
                        if (a[i]=="") {
                            a[i]=" ";
                        }
                    }
                    break;
                case "charcode" :
                    trace("sc.charcode");
                    update(command[2],command[1].charCodeAt(0));
                    break;
                case "store" : 
                    //update(command[0],ScratchStorage.store(command[1]))
                    break;
            }


        }

    }
}

If you're interested in replicating this, you must instantiate a new ScratchSocket and call it's update method:

Code:

var s:ScratchSocket=new ScratchSocket();
s.update(variableName,value)

ehh, what?


@savi3000 | hcsmp.com

Offline

 

Board footer