aceofpack's Forum Posts

  • Thanks but I couldn't download the capx - free hosting 404 page.

  • Not sure what you mean...you haven't described what sort of mouse movement? Do you want something to point at the mouse or follow it? etc..

  • Can you provide some more detail on that statement.

    It reads ThrustTimer = Ship_Thrust.ThrustTimer % 5 = 0..

    There's 2 conditions in there which seems a little odd.

    Since you are setting the ThrustTimer back to 0 anyway, can't you just check for when it's value is equal to 5?

  • Hello all,

    I'm trying to get my head round doing the following set of actions using Construct 2. Could anyone lend me a hand :)

    I have a global var moveID.

    I increment this every time a move command is issued (like press right etc).

    I also add this value to a one dimensional array using [moveID] as the index and then the move value.

    What I want to be able to do, is take any moveID (let's say 100) and the array has values for example to 150. Loop from 100 to the end, extracting the values and adding them to another variable.

    Then delete all the indexed values we just looped through.

    I'm ok doing this in javascript but just need to understand what this will look like in c2.

    Many thanks.

  • Hi all,

    I've applied some mods to the already modified Zack0Wack0's original. Taken from JohnnySheffields version here.

    Here's my version:

    Socket io plugin

    New Expressions:

    Socket.DataAtVAr("variable name") <- this will allow you to select incoming values by using the variable name.

    e.g. if the sever sent {id:5, x:2, y:5} for an event "move player", you can do On event "move player" > Opponent.X = int(Socket.DataAtVar("x"))

    Socket.LoadDataJSONStringify <- this can be injected into a hash table or anything that takes a JSON string.

    New Action:

    EmitAsJSONString <- this will allow you to send data as JSON. It will convert the JSON string to JSON prior to sending. Note, because C2 does not allow using escape characters like \ or the use of single quotes. You need to escape double quotes using "".

    e.g: "{""y"":""" & int(MyPlayer.Y) & """}"

    converts to {y:value}

    I'm finding the DataAtVar and the EmitAsJSONString really workable and much cleaner than the comma values and LastDataElement.

    I'm working on a decent example for you all and a template server file for multiplayer. I'll release that soon for those interested.

    :)

  • I agree, HTML 5 is the future and javascript along with it.

    Scirra, from a business point of view have done the right thing to focus it now so they are in a prime spot in years to come - of which they are already for this corner of the market.

    A platform itself can still be abused, just like any coding language. There's still optimisation tricks to be had. As time goes by maybe we can have a knowledge base of optimisation tricks for common themes - or even a powerful reSharper (http://www.jetbrains.com/resharper/features/code_refactoring.html) type optimisation of javascript for gaming purposes.

    I'm still to test the speed on mobile and Android for certain things but I know there's so much you can do in the way you plan events and the mechanics of your game that will greatly improve performance.

    Believe in the browser, it is the only thing that interprets a common language across all devices. That's power.

  • Great :)

    That works:

    "{""y"":""" & int(MyPlayer.Y) & """}"

    A bit of an eyesore but it works!

  • "{\"y\":\"" & int(MyPlayer.Y) & "\"}" <- gives me syntax error unknown character (pointing to the \).

  • No, it doesn't like the \ either.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 :)

  • 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!