Yet-another Multiplayer Demo (with capx)

Show us your completed creations made in Construct 2

Post » Mon Jul 30, 2012 6:47 pm

@juantar
Thank you. I've been thinking about it.
actually I want to do is to show me on a TV connected to a pc game and use another device as a control. think it's possible and how it could do. that's why I thought that the PC that is connected to the TV could be a player but will have no involvement but I'm still looking how to do that, if you have any idea can help me
B
16
S
3
G
3
Posts: 15
Reputation: 2,813

Post » Tue Jul 31, 2012 4:39 pm

@itza3985 so do you want the game to show in a TV that is connected to the PC but have the controller for the game a spearate device (like an Iphone)?

If that is the case, you could just connect an hdmi cable from your pc to the TV (if your TV supports it) and just set up Windows to output to the TV.

As for the iphone as the game controller, you could create a separate C2 "game" that just shows arrows in the screen. Every time the user clicks the arrows, you can have the socket plugin send a message to the server running in the PC (a node.js script). Once the server running in the pc receives the message, you can have the server script send the message to the C2 game running in the PC. In that game you can just put a logic that says something like if the message from the socket starts with "L" then simulate a LeftArrow.
B
26
S
7
G
3
Posts: 118
Reputation: 4,264

Post » Wed Aug 01, 2012 12:13 am

@juantar i've been following your work for some time now, and your example really inspired me a lot to start digging deeper in Construct and multiplayer stuff.

I'm a kinda self-taught guy with highschool/college/bussines experience in bunch of different languages (starting in '97 with some good 'ole qbasic and GOTO 10, GOTO 20 stuff), but javascript and node really got my boner up, if you now what i mean, so take my words with a grain of salt.

So, after reading some of your code on server example, and zack's socket.io plugin and some hacking with it i realized that if we have just a "send" action which calls Socket.send(data), server will always be a giant if loop, and we'll check messages by splitting received data first, then checking how the first part of your message looks like, and i believe it's not really node-ish to do, because when you start writing some bigger pieces your server code is a giant if(like this sentence), which is constantly evaluated and eventually will be slow(er) and hard to understand.

So i added a "emit" action to the plugin you can emit a custom event to the server. In C2 it is similar to "send", but besides your message, you have to tell it what event are you emitting. Plugin now uses socket.emit('yourevent',"yourdata").

Now server can, instead of looking like this:

socket.on("message", function (data) {
    var new_data = data.split(',');
    if (new_data[0] == 'P') {do something}
      else if (new_data[0] == 'D') {do this}
      else if (new_data[0] == 'L') {do that}

etc...

look like

socket.on("message", function (data) {
    var new_data = data.split(',');
    etc
}

socket.on("yourevent", function (data) {
    var new_data = data.split(',');
    etc
}

and I believe it's much more elegant.


I planned to post my plugin now, but i've found out you released an updated version few days ago so i'll incorporate my edits to your latest version, and put it here so you can check the code and see have i fucked up anywhere.

I also started to hack the plugin so you can trigger custom events inside the plugin (so that server can emit custom events to client), but thats a work in progress.

@itza3985: Actually all this motivation for adding emit function is because we're currently working on something similar to your idea. (By we i mean group of 4 people working on this for last 3 months)

Whole system is made with idea that is reusable for different kind of games, so everyone will be able to connect to our server and implement joystick functionality to your C2 projects. Server is currently hosted on nodejitsu, in my opinion the best Paas currently online (give them a click: http://nodejitsu.com/

I hope to share a demo with you within next 3 weeks (it's online, but we won't share it until it's on some decent level)

@Taurian with "emit" action you'll be able to utilize the room thingy(although you can do it now with "send" also), but it's something you'll have to do on server side, if i'm wrong somebody correct me, give me some guidance and i'll try to incorporate it in the plugin

Whoa, enough for now, wrote too much, will report soon with edited plugin and more info on the joystick thingy.

P.s Has anyone looked into the whole "Socket.io plugin won't minify" thing? In my opinion it's really important to have that problem solved, after i'm done with "emit" thing i'll try put my focus on that!
JohnnySheffield2012-08-01 10:31:44
Be nice until it's time to not be nice
B
36
S
9
G
9
Posts: 293
Reputation: 6,652

Post » Wed Aug 01, 2012 10:22 am

Hi!

I've added some functionality to socket.io plugin, but please don't use this plugin in production code because it isn't tested, verified, and i'm not even sure that it's in strict ECMA (i've done my best, but it's been a really long night)

So, before anything, please somebody double-checks this code, for our own safety.

That said, i've added two new conditions:

OnEventReceived

- triggered when your custom event you specified is received

and

OnAnyEvent

- trigered when any event is received (including connect, message, disconect, your custom events etc... )


one new action:

Emit

- emit a custom event through socket. (You must specify which event, and what data to send with that event)

and one expression:

LastSocketEvent

-where you can get last event that was triggered.


You can check out the great mind-blowing unbelievable test demo with a node server hosted at http://csocket.jit.su/ at:

https://dl.dropbox.com/u/62601881/csocket/index.html

and download a zip file with modifed plugin here:

https://dl.dropbox.com/u/62601881/demo_test.zip


along with simple example server, package.json and a .capx file in a separate folder.


Once again:

I haven't checked is this mod backward compatibile, ECMA strict, or anything, try it, mod it, if you have time, make it better.

Use at your own risk.
JohnnySheffield2012-08-01 10:31:15
Be nice until it's time to not be nice
B
36
S
9
G
9
Posts: 293
Reputation: 6,652

Post » Wed Aug 01, 2012 2:59 pm

@JohnnySheffield awesome job Johnny! I was thinking on using custim events as well in the future. You are right about making the server and client code cleaner. I will try out your plugin when I get a chance this week.

Again, thanks for contributing your work to the community
B
26
S
7
G
3
Posts: 118
Reputation: 4,264

Post » Wed Aug 01, 2012 6:31 pm

@juantar

//warning: insomnia rant:

it nothing compared how much i learned from the community, and socket.io is one of plugins really important and powerful plugins to make construct even more powerful, so i think it's crucial to have it clean and stable as much as possible, and make some pre-made ready-to-use node.js server for the community to use. i think that with good semi-moderate but usable node.js servers on some clouds with good explanations and tutorials will boost the use and knowledge within harmony between construct and node.js and current multiplayer demos/real time usage.

If you asked me yesterday how constructs plugins are made, i wouldn't had an answer, i spent all my free time in last few months to learn node.js and socket.io and etc, and reading this thread yesterday really inspired me to dive in and stop thinking about modding the plugin and just doing it. It was a really a meditative experience, a lot of barriers was passed last night. For somebody maybe not a great success but for me definitively a level up and a big sense of pride for making this mod.

// serious question:

oh, before i forget, let me repeat my question for everybody using socket.io plugins:

whats your knowledge on why socket.io won't minify?

Let solve that thing, i believe it would be a great step forward in making this plugin and a yet another great multiplayer demo as neat as possible!

JohnnySheffield2012-08-01 18:46:24
Be nice until it's time to not be nice
B
36
S
9
G
9
Posts: 293
Reputation: 6,652

Post » Mon Aug 06, 2012 1:06 am

Hi Juantar, I'm fairly new to this scene, but I was checking out your plugin and when getting things installed I keep running into the same error in Node.js.

When trying to "node example_server.js"

I receive the following errors:


Hopefully you can help me out! I'm new to a lot of this socket stuff, but am very interested in getting a multiplayer game working
B
6
Posts: 20
Reputation: 815

Post » Mon Aug 06, 2012 8:45 am

I got everything working and set it up properly, but now I'm wondering how to get rid of characters/avatars/people (The people you play as) when you leave. Because they just stay there and it's quite annoying. Any suggestions?
B
18
S
9
G
5
Posts: 77
Reputation: 4,946

Post » Sat Aug 18, 2012 4:32 am

Use the socket.on disconnect function to broadcast it.
B
7
S
2
G
3
Posts: 3
Reputation: 2,590

Post » Mon Aug 20, 2012 2:58 am

Just finished the reading and I'm very excited about all of the progress that's being made here!

I've been spending a good chunk of my day investigating potential multiplayer implementations in C2, and this appears to be the only one that is really making any progress so far as I can tell.

Outstanding work, from what I can tell, thus far! I look forward to following the progress made here!
B
28
S
6
G
5
Posts: 248
Reputation: 5,463

PreviousNext

Return to Completed Creations

Who is online

Users browsing this forum: No registered users and 8 guests