Discuss Scratch

B1t_Pr0xy
Scratcher
10 posts

Basic JavaScript LAN Connection (Not using Cloud!)

So I am making a simple Maze Game (seen in my other posts) and another guy and I are working on a simple connection between two clients with the game (whether it be the Scratch Offline Editor or Web interface) over a LAN connection (same internet provider). We develop applications together in the same lab in other programming languages (Java, C, Python, etc) and so we want to make a Scratch game that would allow for multiplayer (just 2 player) over our local internet connection.

The only commands I would need would be:
  • SendPos - with the parameters of X & Y (Double-Precision Values)
    ReceivePos - also with the parameters of X & Y, just instead of being set they are being received and setting a variable.
    Connect - with the parameters of IP (maybe?) and Port (again maybe?). Im just guessing on this last one, the top two are really what I need.

I have this block:

(function(ext) {
ext._shutdown = function() {};
ext._getStatus = function() {
return {status: 2, msg: 'Ready'};
};
ext.runCommand = function(x) {
eval(x);
};
var descriptor = {
blocks: [
['', 'Run %s', 'runCommand', 'alert("Hello World");'],
]
};
ScratchExtensions.register('Ultimate extension', descriptor, ext);
})({});

Taken from this page by “Blank1234”.

And it executes raw JavaScript inside the block, and therefore is very open ended but my dilemma is I don't know JavaScript! I attempted looking for some simple pre-written code that would allow for me to Send and receive an X and a Y coordinate over the internet (Using sockets?) but my search kept coming up empty handed. So that's where you incredible developers and modders alike come in.

Can you guys help point me in the direction of a JavaScript example that would allow me to do a simple LAN connection that could send and receive just two Double-precision floating-point values between two computers?
Or if that isn't possible maybe another way to do such a thing? (Not cloud, it is too slow and under powered for what i need).
Pointing me towards other custom blocks/extensions would also be beneficial if they can achieve what I need.
If you need any more information just leave a response asking for clarification and I will respond as soon as possible with an answer to clarify your problems.


I know I'm probably asking a lot, but if this gets working I will release a precoded custom extension (giving credit to all you wonderful coders) that would allow anybody to easily throw this into their program and have a version of multiplayer accessible to all Scratch designers.

Thank you for your consideration, time taken to read this, and future responses I get!
–Pr0xy

Last edited by B1t_Pr0xy (Sept. 25, 2015 15:31:20)

Firedrake969
Scratcher
1000+ posts

Basic JavaScript LAN Connection (Not using Cloud!)

Would ajax work?

'17 rickoid

bf97b44a7fbd33db070f6ade2b7dc549
Jonathan50
Scratcher
1000+ posts

Basic JavaScript LAN Connection (Not using Cloud!)

If you like, you could learn JavaScript.
The ScratchX API is simple if you do know JavaScript.
The documentation for ScratchX is here: https://github.com/LLK/scratchx/wiki
You may be able to use a JavaScript API.
AJAX on it's own couldn't work as you need a server too.
One way may be to have server software running on the computer that is interacted with by sending HTTP requests to localhost using AJAX.

Last edited by Jonathan50 (Sept. 26, 2015 06:40:38)


Not yet a Knight of the Mu Calculus.
hictooth
New Scratcher
4 posts

Basic JavaScript LAN Connection (Not using Cloud!)

Are you sure sending the coordinates over the internet would be too slow? I've tried it (had it running with 10+ computers all moving sprites on everyone's screen, and it worked perfectly. No delay at all.
Znapi
Scratcher
500+ posts

Basic JavaScript LAN Connection (Not using Cloud!)

hictooth wrote:

Are you sure sending the coordinates over the internet would be too slow? I've tried it (had it running with 10+ computers all moving sprites on everyone's screen, and it worked perfectly. No delay at all.
This reminded me that you might not need an extension at all. If everyone playing the Scratch project isn't getting their TCP requests to the cloud variable server blocked by a firewall, then they should not experience too much lag, although it might still be noticeable (more on this here).

Since you say that all of your players will be on a the same LAN, you could try setting up a local, custom cloud variable server in your LAN as well. I am pretty sure this will reduce the lag since it is much, much closer and only two computers will make requests to it. I don't think you will have to worry about firewalls with it either.

Last edited by Znapi (Sept. 27, 2015 18:45:09)

B1t_Pr0xy
Scratcher
10 posts

Basic JavaScript LAN Connection (Not using Cloud!)

So since i'm still considered a “Scratch Newbie” which is pretty aggravating since I would like to have access to cloud data, but i am restricted, is there a way i can still utilize the scratch cloud data? Or a fast track to becoming a “Scratcher”?

Basically, am i aloud to use cloud data for my own program? or am i still limited to that because my account is not older than about 1 month.
liam48D
Scratcher
1000+ posts

Basic JavaScript LAN Connection (Not using Cloud!)

B1t_Pr0xy wrote:

So since i'm still considered a “Scratch Newbie” which is pretty aggravating since I would like to have access to cloud data, but i am restricted, is there a way i can still utilize the scratch cloud data? Or a fast track to becoming a “Scratcher”?

Basically, am i aloud to use cloud data for my own program? or am i still limited to that because my account is not older than about 1 month.
Probably just become a Scratcher. Comment on, love, and favourite projects, share your own projects, and the like.

202e-202e-202e-202e-202e UNI-CODE~~~~~
masterex1000
Scratcher
68 posts

Basic JavaScript LAN Connection (Not using Cloud!)

i recommend using web rct. this can be complicated at first but after a while you will get it. you don't need a server just a browser.

Generation 379: the first time you see this copy and paste it on top of your sig in the scratch forums and increase generation by 1. Social experiment.
azalea3000
Scratcher
2 posts

Basic JavaScript LAN Connection (Not using Cloud!)

} } when {green flag clicked} = {do} turn {left} at angle={90 degrees} JavaScript
azalea3000
Scratcher
2 posts

Basic JavaScript LAN Connection (Not using Cloud!)

@Gamez477 is only 10 and he is learning Javascript I bet he is a genius!
lugga
Scratcher
500+ posts

Basic JavaScript LAN Connection (Not using Cloud!)

First you need to learn how to write executables and how to manage a webserver. Then get a webserver and program a simple application that will do what you want. Upload it on to the web server (this may mean using the terminal / cmd). Write some simple javascript using AJAX to send / receive data). Oh and this will also require you to learn how to handle HTTP get / post requests.
Jonathan50
Scratcher
1000+ posts

Basic JavaScript LAN Connection (Not using Cloud!)

lugga wrote:

First you need to learn how to write executables and how to manage a webserver. Then get a webserver and program a simple application that will do what you want. Upload it on to the web server (this may mean using the terminal / cmd). Write some simple javascript using AJAX to send / receive data). Oh and this will also require you to learn how to handle HTTP get / post requests.
or use websockets…

Not yet a Knight of the Mu Calculus.

Powered by DjangoBB