aceofpack's Recent Forum Activity

  • rexrainbow

    Thanks for your response.

    The problem is that the string: '{"x":"' & MyPlayer.x & '","y":"' & MyPlayer.y & '"}'

    ..is not seen as a string - CS2 doesn't like strings started with ' or using an escape character \.

    I guess i'll have to try and implement the later method you describe.

    Cheers

  • Hello,

    I've been amending the socket.io plugin so I can receive JSON and pick a value and also emit it back.

    I've been successful implementing a new LastDataAtVar("variable") expression which can pick a variable from incoming JSON object.

    e.g. server does:

    this.broadcast.emit("new player", {id: newPlayer.id, x: newPlayer.getX(), y: newPlayer.getY()});

    I can handpick the values.

    However, now I'd like do something like:

    Socket On Event "move player" : Emit '{"x":"' & MyPlayer.x & '","y":"' & MyPlayer.y & '"}'

    The problem is Construct 2 does not allow me to write strings in this way because of the error checking...although it is a string.

    If I could do this, I could then just JSON.parse() it. Even better would be to write JSON directly into the field without it being a string.

    Any ideas on getting around this?

    Cheers

  • Hey Johnny/all,

    dropbox.com/s/095i4mjtkd9pe2y/socket-io-ace.zip

    Not sure if I should do a new post but I've amended the plugin with the following feature:

    LastDataJSONStringify which works well in combo with the hash table plugin:

    scirra.com/forum/plugin-hash-table_topic47637_post298284.html

    So an example use would be to setup a hash table to store incoming values sent from node such as:

    <img src="http://www.stngame.com/images/hashtbl.PNG" border="0" />

    Then, on an event, populate the hash table with the JSON string:

    <img src="http://www.stngame.com/images/event_cs2.PNG" border="0" />

    You can then access the data using:

    int(OtherPlayerData.AtKeys("y"))

    Server code would look something like:

    this.broadcast.emit("move player", {id: movePlayer.id, x: movePlayer.getX(), y: movePlayer.getY()});

    I'm still working on this so likely to release some more stuff soon...

    Sorry for the short explanation but might as well release often just in case it helps folks :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks again Johnny, I will share my progress as it's good for us to advance this concept to a very decent solution.

  • Thanks a lot for your help, much appreciated.

    (Yes, that was my server code btw).

    I was taking a look at the runtime.js and was thinking if splitting the data by commas was the only way.

    Thanks for the clarification. I was thinking of editing it to work with JSON in the way this article discusses:

    buildnewgames.com/optimizing-websockets-bandwidth

    But maybe for now I will concentrate on using CSV's and working on the client-side predicition and interpolating entities parts of multiplayer:

    gabrielgambetta.com (3 parts)

    I'll get pong up on a server and share to test if we can get acceptable real-time results.

  • Thanks for this great plugin but I'm having trouble understanding the LastData bit.

    Why not present data?

    Consider:

    io.sockets.on('connection', function (client) {

            client.userid = UUID();

            client.emit('onconnection', {id: client.id});

            console.log('\t socket.io:: player ' + client.userid + ' connected');

            client.on('disconnect', function () {

                console.log('\t socket.io:: client disconnected ' + client.userid );

            });

         

    });

    I do a connection, then check if any data is available. If I receive an event named 'onconnection' I spit out the alert with Socket.LastData.

    This comes up as 'websocket' before another alert '[Object] [object]' which is the one I want.

    What is this 'websocket', why do we look one step back in time?

    I must be missing something here!

  • erhaps I need to clarify this. What happens is that my server code uses NowJS callbacks that are implemented in the C2 runtime. There's no code from the runtime that runs on the server.

    Ah yes sorry. This is all bespoke. I see now how this works after delving deeper. I was looking at c2runtime.js to see if there could be a way to lift code from it for the server but there are some serious arrays within arrays in there! Not sure how it's structured.

  • Whilst UDP is all well and good. ..Is there perhaps some confusion between that and well designed architecture.

    I believe good multi-player gaming can be achieved with TCP.

    First off all, we need a optimised methods of transit and a means - socket.io. Many guys here have already demo'd the use of this.

    We should, in theory (and with some mods), be able to use c2runtime.js on both server and client side with some 'middleware' that deals with Client Side Prediction and Entity Interpolation.

    gabrielgambetta.com

    buildnewgames.com/real-time-multiplayer

    What's interesting about the above article is the structure of the game:

    client.js - The logic for the game client setup in the browser.

    app.js - The server side app to run on node. This handles all the node/express/socket.io set up and code.

    game.server.js - The logic for the game server (?lobby?).

    game.core.js - The logic for the game play itself, both server and client.

    Until I've created for myself and failed or seen a game output here with these methodologies, I can't believe it can't be done (double negative ;))

  • Sorry, if they need to be 4 different sprites then that wont work. When you say controller? Is this 4 people with control pads on the same computer or over a network?

  • You can spawn 4 instances of the same Object (player sprite) which have instance variable: playerNumber which you make sure is distinct for each player.

    You can then assign control to the instance of an Object that has playerNumber x.

  • Velojet

    No worries, I'm going to explore your code and aim to help you achieve this goal.

    There's good and bad news around this:

    For the non-technical - server software such has node.js has allowed developers to use the same code client and server side. This means that a method of generating code to be inserted server side can be dreamt of. This is what velojet is actually doing here. He's used code from the runtime that he could run on the server.

    However, you need a server for multiplayer.

    Latency and lag needs to be managed effectively with a few methods:

    • The design of your data for the game
    • The amount of players you want on any screen at one time
    • Optimisation to be sent via binary means (this is your data broken down into its component parts with no 'bloat' added)

    Your game needs to design against cheats:

    • Only send a 'request to perform an action' to the server
    • Client makes the move to avoid lag whilst waits for server
    • Server works out where it expects the player should be/what status they are at etc when the message is receivied
    • Client checks if the move is inline with the server when the response comes through and corrects it to the expectation if wildly different

    This is prediction correction. en.wikipedia.org/wiki/Client-side_prediction

    So, there's a few things here that make multi-player not so simple as a plugin. You need to be able to design your game in a way to be optimised for multi-player.

    Cheaters especially need to be quelled if you want to do in-app purchasing developers.google.com/commerce/wallet/digital

    I'm working on all this and like velojet, it's important to get an example working with the steps you take to even think about what elements are needed to give a true multiplayer plugin.

  • Huge thanks for this.

    I've been doing some research into this too in the hope to build a fast multiplayer game...partially using construct 2.

    This article is excellent: buildnewgames.com/optimizing-websockets-bandwidth

    It discusses using binary to send game data which I think is a big consideration in improving the plugins created.

    You also need a way to port code to a server side environment so construct 2 would need a way to export in that way to avoid cheating.

    I look forward to seeing what comes of it in the near future :)

aceofpack's avatar

aceofpack

Member since 29 Jan, 2013

None one is following aceofpack yet!

Trophy Case

  • 11-Year Club
  • Email Verified

Progress

12/44
How to earn trophies