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

#26 2009-01-30 22:42:46

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

Re: scratch networking commands with actionscript 2.0

You Did It Archmage and Chalkmarrow!!!!!!! Congratulations!!!!!!!  big_smile

Offline

 

#27 2009-01-30 22:48:05

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

Re: scratch networking commands with actionscript 2.0

More like Chalkmarrow did it  tongue

I probably wouldn't have figured out the correct commands.


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

 

#28 2009-01-31 09:19:02

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

Re: scratch networking commands with actionscript 2.0

archmage wrote:

More like Chalkmarrow did it  tongue

I probably wouldn't have figured out the correct commands.

You would have figured it out. I just found the right websites to copy from (I mean "remix").

The key thing is, what kinds of creative things can be done once the Flash to Scratch connection is in place?

Last edited by chalkmarrow (2009-01-31 09:19:20)

Offline

 

#29 2009-01-31 10:05:33

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

Re: scratch networking commands with actionscript 2.0

I am going to try make a tag like game today using the networking features. I will upload the source files on to the scratch connections wiki when I am done.


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-01-31 10:54:52

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

Re: scratch networking commands with actionscript 2.0

Can You Upload It On This Website Too? I Won't Be Able To Find Them On That Site.

Offline

 

#31 2009-01-31 11:09:24

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

Re: scratch networking commands with actionscript 2.0

Sure, but it will only work if you download the project to your computer. Also one person has to have the flash file running on their computer.

Magnie, if you want I can face you in a game of scratch tag when I am done coding it  smile


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

 

#32 2009-01-31 20:35:00

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

Re: scratch networking commands with actionscript 2.0

I am in the process of coding a tag game in scratch but this piece of action script is giving me problems.

Code:

function dataInHandler(event:ProgressEvent):void {
    var inString:String=mySocket.readUTF();
    trace(inString);
    var inString2:String=friendSocket.readUTF();
    trace(inString2);
}

The two sockets are connected in the same way as they are in chalkmarrow's post. It works if I comment off one of the traces like this:

function dataInHandler(event:ProgressEvent):void {
    var inString:String=mySocket.readUTF();
    trace(inString);
    //var inString2:String=friendSocket.readUTF();
    //trace(inString2);
}

But I want both values to be read. Help would be appreciated.


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

 

#33 2009-01-31 23:24:46

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

Re: scratch networking commands with actionscript 2.0

Hmm. I think you might have to have a separate dataInHandler for each socket.

Offline

 

#34 2009-01-31 23:26:54

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

Re: scratch networking commands with actionscript 2.0

Ummm I am not sure how to do this.

EDIT: I figured out what to do. Its hard to get some stuff right when you copy and paste without checking out what everything does  tongue

Last edited by archmage (2009-02-01 00:12:38)


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

 

#35 2009-02-01 14:10:28

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

Re: scratch networking commands with actionscript 2.0

I am having some problems with data transfer. As a test I tried to transfer the x position and it put it to the wrong values.

Here is the source http://www.filesavr.com/untitled-4

I tried this on 2 of my computers. It did receive and send an x position but I was the wrong value. So my sprite was moving but to the wrong x position.


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-02-02 08:02:32

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

Re: scratch networking commands with actionscript 2.0

archmage wrote:

Magnie, if you want I can face you in a game of scratch tag when I am done coding it  smile

That Would Be Awsome! But I Don't Think I Have Flash Needs To be .exe or .py I think.

Offline

 

#37 2009-02-02 09:03:12

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

Re: scratch networking commands with actionscript 2.0

Magnie wrote:

archmage wrote:

Magnie, if you want I can face you in a game of scratch tag when I am done coding it  smile

That Would Be Awsome! But I Don't Think I Have Flash Needs To be .exe or .py I think.

The flash file is .exe

But only 1 of the 2 people actually need the flash file running anyways so all you would need to download is the project.


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

 

#38 2009-02-02 09:08:43

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: scratch networking commands with actionscript 2.0

hmm, we could be opening a gateway for the team to work on netscratch  smile  gl continuing withyour tag game  tongue

Offline

 

#39 2009-02-02 09:23:16

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

Re: scratch networking commands with actionscript 2.0

archmage wrote:

Magnie wrote:

archmage wrote:

Magnie, if you want I can face you in a game of scratch tag when I am done coding it  smile

That Would Be Awsome! But I Don't Think I Have Flash Needs To be .exe or .py I think.

The flash file is .exe

But only 1 of the 2 people actually need the flash file running anyways so all you would need to download is the project.

Ok  smile  I Can't Wait. EEK

Offline

 

#40 2009-02-02 09:31:48

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

Re: scratch networking commands with actionscript 2.0

Hopefully, I can get it working soon. It doesn't seem to want to cooperate.


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

 

#41 2009-02-02 09:42:24

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

Re: scratch networking commands with actionscript 2.0

[blocks]<broadcast[ Cooperate ]
[/blocks]

Offline

 

#42 2009-02-02 20:07:10

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

Re: scratch networking commands with actionscript 2.0

Here is a video of me using scratch's networking features with flash.
http://ca.scratch.mit.edu/ext/youtube/?v=hYrK-fdymDk&feature=email

It seems to send and receive broadcast message just fine but the values of the transmitted variables get messed up. This means that I could easily make a game like rock paper scissors (broadcasts are needed only).


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

 

#43 2009-02-02 21:11:40

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

Re: scratch networking commands with actionscript 2.0

That's amazing. If you can pull that off it will be very impressive.I haven't had a chance to look at the .fla file you linked to, since I only have CS3 on one computer. But I'll look at it by tomorrow. What is the failure mode? Are the sensor variables being scrambled in  a consistent way? I'm assuming you're sending integers, though I haven't looked at the .sb file either...

Offline

 

#44 2009-02-02 21:31:38

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

Re: scratch networking commands with actionscript 2.0

Ok, in the video I ran a simple test to see if the variable values were consistent between my 2 computers. Every second a variable is increased by 1. The 2 values start off similarly but the receiving computer doesn't receive messages properly. In my video, when my variable was 26 on the recieving computer my variable on my other computer was 62 and the receiving computer continued to lag behind. I tried another test that added and subtracted a variable but the receiving computer would do strange things like add the variable even if I was trying to subtract from it. The 2 variables on my different machines were very inconsistent and they were not being scrambled consistently. The only consistency was that they both received the messages at about the same time.

Here is the flash CS3 version of the fla if you want to look at the code
http://spamtheweb.com/ul/upload/020209/77446_NetTest.fla

Last edited by archmage (2009-02-02 21:38:15)


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

 

#45 2009-02-02 21:49:58

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

Re: scratch networking commands with actionscript 2.0

Ah. Ok. I remember that when I was making my Processing program that interfaced with Scratch I had the same problem because the buffer filled up with sensor updates and broadcasts so fast that one or more of the programs couldn't keep up. Every broadcast and variable change gets sent out over the socket, so what I had to do was come up with a way to ignore the things I didn't care about. The buffer has to be cleared out as fast as possible. Though if the variable is only being updated every 1.0 seconds, I can't imagine that that would be a problem. I'll see if I can help puzzle it out.

Update: Can you cut and paste the script in plaintext? The .fla file is giving CS3 a problem ("unexpected file format").

Last edited by chalkmarrow (2009-02-02 22:08:12)

Offline

 

#46 2009-02-04 16:09:19

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

Re: scratch networking commands with actionscript 2.0

Archmage: Can I Make The Tag Game or do you need to make it in a special way?

Offline

 

#47 2009-02-04 16:24:45

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

Re: scratch networking commands with actionscript 2.0

chalkmarrow wrote:

Ah. Ok. I remember that when I was making my Processing program that interfaced with Scratch I had the same problem because the buffer filled up with sensor updates and broadcasts so fast that one or more of the programs couldn't keep up. Every broadcast and variable change gets sent out over the socket, so what I had to do was come up with a way to ignore the things I didn't care about. The buffer has to be cleared out as fast as possible. Though if the variable is only being updated every 1.0 seconds, I can't imagine that that would be a problem. I'll see if I can help puzzle it out.

Update: Can you cut and paste the script in plaintext? The .fla file is giving CS3 a problem ("unexpected file format").

Sure, but I also posted what should be a cs3 version as well.

My flash has 2 buttons, an input text field (for the IP) and 2 other dynamic text fields that state the status of the connection.

Code:

var mySocket=new Socket();
var friendSocket=new Socket();
var dataOut:String;
var player1Connected:Boolean;
var player2Connected:Boolean;
var player1X:String;
var player2X:String;
var player1Y:String;
var player2Y:String;
var test:String;
myStatus.text=String("Waiting to connect to your computer");
friendStatus.text=String("Waiting to connect to your friends computer");
var socketNum:int=1;
inputIP.text='192.168.1.103';

my_btn.addEventListener(MouseEvent.CLICK, enterMyIP);
function enterMyIP(evt:MouseEvent):void {
    socketNum=1;
    mySocket.connect("localhost",42001);
    mySocket.addEventListener(Event.CONNECT,socket);
    mySocket.addEventListener(Event.CLOSE,socket);
    mySocket.addEventListener(IOErrorEvent.IO_ERROR,socket);
    mySocket.addEventListener(ProgressEvent.SOCKET_DATA, dataInHandler);
}

ip_btn.addEventListener(MouseEvent.CLICK, enterIP);
function enterIP(evt:MouseEvent):void {
    socketNum=2;
    //192.168.1.103
    friendSocket.connect(inputIP.text,42001);
    friendSocket.addEventListener(Event.CONNECT,socket);
    friendSocket.addEventListener(Event.CLOSE,socket);
    friendSocket.addEventListener(IOErrorEvent.IO_ERROR,socket);
    friendSocket.addEventListener(ProgressEvent.SOCKET_DATA, fdataInHandler);
}

function socket(Event):void {
    if (socketNum==1) {
        switch (Event.type) {
            case 'ioError' :
                myStatus.text=String("Cannot connect to your computer");
                break;
            case 'connect' :
                myStatus.text=String("Connected to your computer");
                player1Connected=true;
                if (player1Connected==true&&player2Connected==true) {
                    SendToScratch('broadcast "StartGame"',1);
                    SendToScratch('broadcast "StartGame"',2);
                }
                break;
            case 'close' :
                myStatus.text=String("Cannot connect to your computer");
                break;
        }

    } else {
        switch (Event.type) {
            case 'ioError' :
                friendStatus.text=String("Cannot connect to your friends computer");
                break;
            case 'connect' :
                friendStatus.text=String("Connected to your friends computer");
                SendToScratch('sensor-update "Scratch-playerNumber" 2',2);
                player2Connected=true;
                if (player1Connected==true&&player2Connected==true) {
                    SendToScratch('broadcast "StartGame"',1);
                    SendToScratch('broadcast "StartGame"',2);
                }
                break;
            case 'close' :
                friendStatus.text=String("Cannot connect to your friends computer");
                break;
        }
    }
}
//sendToScratch('broadcast "StartGame"');

function SendToScratch(dataOut:String,playerNum:int) {
    var sizeBytes:ByteArray = new ByteArray();
    sizeBytes[0]=0;
    sizeBytes[1]=0;
    sizeBytes[2]=0;
    sizeBytes[3]=dataOut.length;
    if (playerNum==1) {
        mySocket.writeBytes(sizeBytes);
        mySocket.writeMultiByte(dataOut, "us-ascii");
        mySocket.flush();
    } else {
        friendSocket.writeBytes(sizeBytes);
        friendSocket.writeMultiByte(dataOut, "us-ascii");
        friendSocket.flush();
    }
}

function dataInHandler(event:ProgressEvent):void {
    var inString:String=mySocket.readUTF();
    //trace(inString);
    SendToScratch(inString,2);

}

function fdataInHandler(event:ProgressEvent):void {
    var inString2:String=friendSocket.readUTF();
    //trace(inString2);
    test=inString2.substring(0,39);
    if (test.charAt(0)=='s') {
        trace(test);
    }

    SendToScratch(inString2,1);
}

Last edited by archmage (2009-02-04 16:28:17)


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-02-04 16:26:49

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

Re: scratch networking commands with actionscript 2.0

Magnie wrote:

Archmage: Can I Make The Tag Game or do you need to make it in a special way?

The tag game won't be any good if I can't get the online connection thing to work first. Just wait, I will let you know when it works 100%.


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

 

#49 2009-02-04 16:42:20

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

Re: scratch networking commands with actionscript 2.0

Ok  smile

Offline

 

#50 2009-02-06 12:43:54

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

Re: scratch networking commands with actionscript 2.0

Ummm if anyone knows how to help with my problem I would really appreciate it if they could let me know how to fix this.

If no one knows there are other programming forums I can consult.


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

 

Board footer