WebSockets: What do you want?

0 favourites
  • I also read in a forum post that someone fixed a problem by setting protocol to something ... meaning yes, use it. Right now, it's set to null.

  • Firebug is telling me that it's continuously reloading localhost:5000

  • Not sure what that could be, but you might as well stop looking at the code from C2's side its just one big json interpreted by the engine.

    C2 has a built in debugger, its actually a lot like Firebug, or Chromes.

    Eventing also can be a bit hard to get the hang of at first.

    You have to remember the events run in order top down every tick.

    The capx I made just shows how to deal with the server so that the server doesn't have to send every tick, just when something changes.

    Sending back to the server is a different story, its a little more complicated.

    Right now your options are to monitor the key presses, and send that when something changes, or monitor the objects x,y, speed, angle, etc and send that data... when something changes. Obviously the former being less exact.

    Or another option is to change the the movement, and set up a timer.

    Something like on this Boolean start a timer, while the timer is running move until the timer is over, and when it ends reset the Boolean.

    And yes the forum time out is a pain.

  • Are you sure that the free version has a debugger? After my first day, which is a little hazy, I have to go back again and let things settle in. I now feel slightly more oriented, as though the day of understanding will in fact one day come. But I think I tried to click on some debugging stuff yesterday and found that it wasn't supported in the free version.

    I don't need anything too fancy just to do this experiment / proof of concept thing. If I can get it to send a clear message that I pressed the right arrow (or JSON action description that goes with it or whatever), I can just maybe reverse it ... send back left arrow command; or something like that.

    Was thinking about this yesterday ... the very first experiment doesn't even require two players. If I do the above, pressing right moves the sprite right, followed by returning to its original position in response to the reverse echo ... or ... maybe right + up or something, since if right + left happens too fast, it could look like nothing happened.

    That would be very, very simple to do as long as the action sends a message to the server that I can modify and send back, and when received, the demo will carry out the new action.

  • OK, the fog has started to clear a bit perhaps. I added a websocket action to each of the key events; sending a simple text message "right" "left" "up" and "down" to the server. Problem is, that there is a loop. When I start running it, it connects to the server and then sends text messages "right" "left" "up" and "down" over and over ad infinitum, even though I haven't pressed any of the keys.

    So far, I'm just doing this with my demo server app ... which is nothing more than a simple echo server. So, the server does send back "right" "left" "up" and "down" in response to receiving those ... it just echos back what it receives. There is an exception. At first, I separately send back some text commenting on the WebSocket server, but I don't think there's any way for the app to respond to any of that ... it would just be uninterpretable text input to the app.

    There may be no way for me to do this without studying the documentation and really understanding it all better.

  • I stopped the loop by setting key event values to 1 (leaving the initial dictionary settings at 0). I just imagined this representing 0 for false and 1 for true. Then the sprite works properly. But not only did the message to server loop stop, but now no messages are received at all; indicating that it's no longer executing the websocket text message sends that I added.

    I keep scrolling through the beginners tutorial and documentation in an effort to get a hint. But beyond generalities ... like add events and actions, then set values for parameters, they don't seem to get into much detail.

  • Why don't I have keyboard events? Wouldn't that be the most straight-forward way to do this?

  • The mouse, keyboard as well as touch are all separate objects you have to add one by one.

    Also if you get the ribbon on top to maximize you should see the debugger icon which is available to all versions on preview. Not sure what the keyboard shortcuts are.

  • I think I'm making progress. I deleted all the dictionary definitions from On Start of Layout and all the Simulate 8 Direction from dictionary key actions. I added Sprite 8Direction is moving event with a websocket text message action. Now the sprite action works and I get the text message at the server each time I move the sprite. I actually get the text message 7 times, each time I click an arrow; but it actually looks like one click of an arrow might respond with several movements in the same direction.

    I've seen the instructions for drop-n-drag adding addons, but don't know where to find the mouse, keyboard, etc. to add them. I found them under templates, but those are not .c2.... files.

  • 8Direction is moving isn't specific. Seems like if I could get keyboard installed, it work ... could specify right, left, etc. with that and it might fire only once per trigger.

  • OK, Keyboard installed. It's easy once you know how. Now I just have to figure out how to use it.

  • Perfect.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Time to switch over to what the input from the server should look like.

  • Well if the return string was already formatted to "{"c2dictionary":true,"data":{}}" then when you received the message you could just load it into the dictionary object, and compare known keys, or do a for each key.

    I would assume there shouldn't be many issues reloading the dictionary that way.

    Newt:

    Could you give a more complete example of the JSON string? I think the only condition is that the string doesn't simulate clicking an arrow key. Since I use arrow keys (keyboard) to trigger sending the message to the server, seems like that would put it in an infinite loop.

    If there's a manual section that gets into this detail, that would be great. But for starters, I could use any response except right, left, up, down arrow keys.

  • this sounds juicy...

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