WebSockets: What do you want?

0 favourites
  • You can add an action to the on start of layout to download the contents of the dictionary as json.

    This is what that string would look like:

    {"c2dictionary":true,"data":{"right":0,"left":0,"up":0,"down":0}}

    So basically you could just concatenate your data with an &:

    {"c2dictionary":true,"data":{&your data&}}

  • One small step for mankind: Added Sprite rotate 45 degrees to Websocket onmessage. That works. So, I am sending and receiving from the server and getting a response on receiving. Need to know I can control specifics better than this of course. :)

  • thanks for responding newt;

    Keeping in mind that I don't use JSON (normally, but will this time and happy to learn if this is what's needed) and am new to Construct 2.

    I'm clicking Add action next to On start of Layout and selecting dictionary, and then .... ???    JSON Load??? enter string above?

    Then what I need to receive is; for example ??

    {"c2dictionary":true,"data":{"right"}} ????

    Or is there some way for me to enter my own logic to do that concatanation ....

    Or does it just know because "right" is now defined in the dictionary?

  • Maybe this is why I was getting the infinite loop. The first version used dictionary definitions. Merely defining right, left, up, and down = 0 was enough to create the loop. That could show it's on the right track, but I need to be able to stop the loop. It could be stopped by the server if there is more than on sprite (or player). The server could match sprite with sender and not pass information back if they don't match. But that's less efficient than dealing with it on the browser end, because it would produce a lot of unnecessary sends.

  • this sounds juicy...

    :) .... Seems to be getting there.

    step by agonizing step (lol)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've set up another server and am modifying the responses. If I'm not mistaken, the JSON command is in the form Keyboard.OnKeyPressed.Right or something like that.

  • You can add an action to the on start of layout to download the contents of the dictionary as json.

    This is what that string would look like:

    {"c2dictionary":true,"data":{"right":0,"left":0,"up":0,"down":0}}

    So basically you could just concatenate your data with an &:

    {"c2dictionary":true,"data":{&your data&}}

    SUCCESS! of a sort. Had to escape the double quotes to make it work and I apologize for my initial confusion. I've been using JSON like objects for many years without ever calling them JSON or using any special JSON processing objects. They're JavaScript objects. Easy enough to roll my own. :)

    I'm now using czsx for right,left,up, down to send websocket messages. "right" "left" etc. are defined in the dictionary and Key "up" = 0 ... event triggers sprite simulate 8Direction up as per the first suggestion.

    I can use the arrow keys and they work locally but do not send any websocket message. Since I haven't coded for multiplayer (all I'm doing on the server end is sending back a JSON string with right, left or whatever in it) ... using different keys to send the websocket message avoids the infinite looping.

    What I'm getting now though is if I press S for up, for example, the sprite continues moving up until I click another button. I'll start looking. I think maybe there's a way to reset the value or something.

  • Yeah you can either have the server send a 0 after x amount of time, or have the client do it.

    Of course if the client does it you run the chance of getting out of sink.

    Then again the ideal method would be to do all the movement on the server, and just update the position data, then all the client would do is interpolate the xys, etc.

  • Tried initializing dictionary values to 0 and conditioning movement on a value = 1. That in itself still works as above .. continues movement until another key is pressed. Then I added Set &Key& = 0 after the 8Direction simulation in each.

    I can tell that the event is still triggered because the sprite changes shape to indicate direction. But it doesn't move at all now. I'm guessing that the reset happens before the movement occurs and stops the movement.

  • Yeah you can either have the server send a 0 after x amount of time, or have the client do it.

    Of course if the client does it you run the chance of getting out of sink.

    Then again the ideal method would be to do all the movement on the server, and just update the position data, then all the client would do is interpolate the xys, etc.

    Would rather not try to keep the server in sync with game calculations. It would seem practical if I could just yank the new pos info and send it to the server for distribution.

    In order to make this work really well, maybe I'll have to dive into the SDK and build a plugin. I'd rather not make that decision at this point though ... with so little experience with Construct 2. I'm starting to wonder how cooperative the Scirra team might be if I get all fired up about doing this.

  • Adding a wait in between makes the simple demo more convincing. It's not performing the same operation as the arrow keys. I think that's the core problem here. Anyways ... this may be enough for my very first proof of concept experiment. You're right on track newt ... next step is to think about what it would take to assure things are in sync.

    Whether or not this can work really well can depend on whether I can get a solid understanding of how Construct 2 works and whether I'll be able to perform the operations of the game via server input (if I may think in print by stating the obvious).

    It seems quite oriented to people who don't program so I'm wondering if they're just not going to be interested in sharing any detailed technical information. I know there's an SDK. Maybe that's enough.

  • Yeah you can either have the server send a 0 after x amount of time, or have the client do it.

    Of course if the client does it you run the chance of getting out of sink.

    Then again the ideal method would be to do all the movement on the server, and just update the position data, then all the client would do is interpolate the xys, etc.

    Seems like I always have to think at least twice whenever you post. :)

    I recalculated and kept track of position in a robot control center I built to demo the prototype of the HLL Framework ... at that time using a workaround for websockets since they didn't exist yet. Then passed position information to the browser that controlled an SVG object that moved around in an image of rooms (walls and doors).

    That was ok.

  • Now I've even exported to HTML 5 and put it on my dev system's server. Only works when I have the two servers running though. Dev system isn't the same as the demo computer I'm running for the other WebSocket demo ... which is full time.

    Arrows cause movement but do nothing with websocket. czsx send r, l, u, d websocket commands which are returned as JSON strings. You get approx. the same movement with both.

    isr.servequake.com/WSGameTest

  • So, my next question is: How does the HTML 5 page work? c2runtime is rather small. Does that load and provide all the needed support? Even for the webocket calls? Or does anyone who uses this have to have a game engine installed first?

  • Its all Html5 standard. The idea was no dependencies, no plugs.

    Just think of each C2 game as blind mini server.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)