[PLUGIN] Zack0Wack0's Construct 2 Plugins

Post your completed addons to share with the community

Post » Fri Jul 08, 2011 7:20 am

Source code available on Github

Changelog

07/01/12
Socket: Upgraded socket.io version. Writing a tutorial.

19/09/11
Sockets: Fixed to work with the API changes.
WebSockets: Now supports the new mozilla version of WebSockets. It's probably going to screw up compatibility on the server side, but if you have a good server it should be able to work with both of them.
Storage: Fixed to work with the API changes.

09/08/11
Socket: Messages are now stored in a data stack to prevent packet loss.

Plugins

Socket (Cross-browser version) - Download


The cross-browser version of the Socket plugin is powered by socket.io, which is a JavaScript library that aims to allow real-time streaming web connections for all browsers that it can. Socket.IO first tries with WebSockets, if they're not supported then it tries Flash sockets (which are basically the same as WebSockets - asynchronous, and fast - however not supported by Construct due to not being able to bundle resources) which are usually supported by every browser because practically every one has Flash. If Flash isn't supported then it tries XHR multiparting, which is a way to make XMLHTTPRequests (ie. AJAX) stream connections. If even that isn't supported, it then tries JSONP polling and XHR polling.

Socket.IO needs a custom server. The default server is built in node.js, which is actually server-side JavaScript (and powered by the same engine that Construct uses for JavaScript). I would highly suggest using this version of socket.io, as it works perfectly. You can see a list of Socket.IO servers here, at the bottom of the page, and there's pretty much a server for all the good networking supported programming languages (perl, ruby, python, java, etc).

If you want to use node.js (suggested), then you will need to install it and then install the socket.io module via the command line (npm comes when you install node.js):

[code]
npm install socket.io
[/code]

There is an example server and client inside the zip file. You can also read the quick tutorial linked in the tutorials section below.

Socket (WebSocket version) - Download

The WebSocket version of the Socket plugin works using WebSockets, a new HTML5 standard. Unfortunately WebSockets support has been dropped by Firefox and Opera because the specification was flawed, so this version only works in Google Chrome and WebKit based browsers. You can enable WebSockets by command line though, if you want to play around with it in other browsers, google it.

Obviously due to the fact that this is a socket you need a server on the other side to communicate with. This version of the Socket plugin supports normal WebSocket servers. If you google 'WebSocket server' you'll find a server that works in a language that you like, and then you can program the server-side stuff. You won't be able to make a server as easily as you can make a game in construct, you'll have to put in hard code.

I've included an example .capx in the download. This example connects to the echo.websocket.org server, which sends back anything that you send towards it. When the 'Echo test' message pops up (at least it should if its working), that means that the echo.websocket.org server has sent back the 'Echo test' message that the socket in the example sends towards it.

NOTE: DON'T USE THIS UNLESS YOU HAVE TO. The specifications for WebSockets are very dodgy, and this is only here for people who really-must use WebSockets with a pure WebSocket server for some strange reason. The cross browser version of the plugin is much better.

Storage - Download
The Storage plugin allows you to store data in the browser. There are two places to store the data: Session Storage, which is available in your current HTTP session; and Local Storage which is available forever (or until the user clears there browser cache, as far as I know).

The 'Store * data' actions take a key and the value to store. The key is simple something to remember the data by so you can use the data later. The value is a value, simply.

The '* Storage supported' conditionals are to check whether the browser supports each storage type. You'll find a large majority of browsers that support the HTML5 Canvas support HTML5 DOM Storage, therefore any browser that can render Construct 2 games will support this plugin.

The '* data exists' conditionals are to check whether the key has data set to something in the storage.

The 'Get * data' expressions allow you to fetch data from storage. They take the key which is the key that you used to set the value originally.

NOTE: This is deprecated. This was implemented as an official plugin, so there's no point downloading it.

Installation

Simply extract the file into your plugins directory, by default at C:\Program Files\Construct 2\exporters\html\plugins.

Tutorials
TODOZack0Wack02012-01-08 03:38:55
B
3
S
1
G
3
Posts: 49
Reputation: 1,148

Post » Fri Jul 08, 2011 10:36 am

Awesome! Thanks for sharing Zack0Wack0
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Fri Jul 08, 2011 2:30 pm

Great work! I was going to write a storage plugin at some point, but you beat me to it. Well done!
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Fri Jul 08, 2011 3:24 pm

Thanks, I really like the new plugin system.

I have some more ideas that I'll make:
Box2D physics (I already implemented this in my game engine so I know what to do)
Run time image manipulation (again, done this before)

I also really want to help with the engine
B
3
S
1
G
3
Posts: 49
Reputation: 1,148

Post » Fri Jul 08, 2011 4:25 pm

[QUOTE=Zack0Wack0] Thanks, I really like the new plugin system.

I have some more ideas that I'll make:
Box2D physics (I already implemented this in my game engine so I know what to do)
Run time image manipulation (again, done this before)

I also really want to help with the engine[/QUOTE]

That's good news. Was worried we wouldn't get something like the image manipulator.
Now if we could get something like distort map with z heights....
B
1
G
1
Posts: 7
Reputation: 439

Post » Fri Jul 08, 2011 5:16 pm

Hi, thanks for the plugin.
I have a question:
Can I put a variable in key, so i can storage automatically a set of data?
In this case, an array.

Edit: Nevermind, I alredy did it. Thanks again.
If i have lucky, by the end of the day i will present to you one of the first games made with C2 with game savings options.
Edit2: Wow, alredy made the save system, and it store the 24336 pieces of data of the array that contains the whole world in 20 seconds!!!
Edit3: Look how is going: Enter the game, pres new, then, wait a few seconds and press S in your keyboard. When it finish, reload the game. Then enter to saved and watch.
Go to the projectarandaschimpf2011-07-08 20:50:03
B
16
S
3
G
6
Posts: 19
Reputation: 3,204

Post » Sat Jul 09, 2011 2:02 am

Also, I forgot to mention the maximum amount of space the storage can hold. 5mb for most browsers (Chrome, Firefox, Opera, Safari, etc) and 10mb for Internet Explorer 8 - 10.
B
3
S
1
G
3
Posts: 49
Reputation: 1,148

Post » Sat Jul 09, 2011 2:47 am

I just use like 23kb and it looks like a huge ammount of data, so temporally i think that 5mb is enough.
B
16
S
3
G
6
Posts: 19
Reputation: 3,204

Post » Sat Jul 09, 2011 6:00 am

Well, I'm unable to edit the OP, so I'll just put this here.

Socket (WebSocket version) - Download 1

The WebSocket version of the Socket plugin works using WebSockets, a new HTML5 standard. Unfortunately WebSockets support has been dropped by Firefox and Opera because the specification was flawed, so this version only works in Google Chrome and WebKit based browsers. You can enable WebSockets by command line though, if you want to play around with it in other browsers, google it.

Obviously due to the fact that this is a socket you need a server on the other side to communicate with. This version of the Socket plugin supports normal WebSocket servers. If you google 'WebSocket server' you'll find a server that works in a language that you like, and then you can program the server-side stuff.

I've included an example .capx in the download. This example connects to the echo.websocket.org server, which sends back anything that you send towards it. When the 'Echo test' message pops up (at least it should if its working), that means that the echo.websocket.org server has sent back the 'Echo test' message that the socket in the example sends towards it.


Socket (Cross-browser version) - Download 1


The cross-browser version of the Socket plugin is powered by socket.io, which is a JavaScript library that aims to allow real-time streaming web connections for all browsers that it can. Socket.IO first tries with WebSockets, if they're not supported then it tries Flash sockets (which are basically the same as WebSockets - asynchronous, and fast) which are usually supported by every browser because practically every one has Flash. If Flash isn't supported then it tries XHR multiparting, which is a way to make XmlHTTPRequests (ie. AJAX) stream connections. If even that isn't supported, it then tries JSONP polling and XHR polling.

Unfortunately, Socket.IO has a rather limited amount of servers you can use. I suggest Tornadio, which is an extension of the Python module tornado. Its the module I used to write the test echo server in. The server.py file is also available in the download. You should note, that in order for Flash sockets to work, there also needs to be a flashpolicy.xml file with the server which has been included as well.

You can see a list of Socket.IO servers here, at the bottom of the page, and there's pretty much a server for all the good networking supported programming languages (perl, ruby, python, java, etc). The default server is written in node.js which is a really nice server-sided implementation of JavaScript for server-networking, it's also using the same JavaScript engine, v8, as Construct 2 (I think..). I had to use version 0.6 of Socket.IO due to the fact that the new version doesn't work too well with Tornadio.

I'm not too sure about Flash sockets as well, I believe that they will work however if you can't get them to work try including the WebSocket Flash (.swf) files included in the download.

All in all, it should work nicely. I've written a multi-player game before with the Socket.IO library and I got it working in Opera. If there are any issues with this version, just post them here and I'll try and fix them.
B
3
S
1
G
3
Posts: 49
Reputation: 1,148

Post » Sat Jul 09, 2011 11:44 am

Once again, I'm unable to edit my posts, so I'll just double post.

I've started the Physics behavior, see the really (broken) test here.
There's a few problems currently, I also need some engine changes from Ashley.

1. You'll notice as you click (spawning new objects) the physics processes speed up. This is because I can't get my head around the logic to make it tween properly.
2. In order for me to continue with this, I need onDestroy functions (so I can remove the rigidbody from the box2d world) and a way to move the box2d body when the object's position and angle are changed from events. These aren't available in the engine at the moment.
B
3
S
1
G
3
Posts: 49
Reputation: 1,148

Next

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 6 guests