You Did It Archmage and Chalkmarrow!!!!!!! Congratulations!!!!!!!
Offline
More like Chalkmarrow did it
I probably wouldn't have figured out the correct commands.
Offline
archmage wrote:
More like Chalkmarrow did it
![]()
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
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.
Offline
Can You Upload It On This Website Too? I Won't Be Able To Find Them On That Site.
Offline
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
Offline
I am in the process of coding a tag game in scratch but this piece of action script is giving me problems.
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.
Offline
Hmm. I think you might have to have a separate dataInHandler for each socket.
Offline
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
Last edited by archmage (2009-02-01 00:12:38)
Offline
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.
Offline
archmage wrote:
Magnie, if you want I can face you in a game of scratch tag when I am done coding it
![]()
That Would Be Awsome! But I Don't Think I Have Flash Needs To be .exe or .py I think.
Offline
Magnie wrote:
archmage wrote:
Magnie, if you want I can face you in a game of scratch tag when I am done coding it
![]()
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.
Offline
hmm, we could be opening a gateway for the team to work on netscratch
gl continuing withyour tag game
Offline
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
![]()
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
I Can't Wait. EEK
Offline
Hopefully, I can get it working soon. It doesn't seem to want to cooperate.
Offline
[blocks]<broadcast[ Cooperate ]
[/blocks]
Offline
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).
Offline
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
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)
Offline
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
Archmage: Can I Make The Tag Game or do you need to make it in a special way?
Offline
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.
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)
Offline
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%.
Offline
Ok
Offline
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.
Offline