WebSockets: What do you want?

Post your work in progress addons and get feedback

Post » Sun Sep 08, 2013 12:52 pm

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&}}
Image ImageImage
B
172
S
50
G
184
Posts: 8,444
Reputation: 116,107

Post » Sun Sep 08, 2013 12:53 pm

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. :)
B
6
S
1
Posts: 76
Reputation: 606

Post » Sun Sep 08, 2013 1:00 pm

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?
B
6
S
1
Posts: 76
Reputation: 606

Post » Sun Sep 08, 2013 1:09 pm

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.
B
6
S
1
Posts: 76
Reputation: 606

Post » Sun Sep 08, 2013 1:12 pm

[QUOTE=harrio] this sounds juicy...[/QUOTE]

:) .... Seems to be getting there.
step by agonizing step (lol)
B
6
S
1
Posts: 76
Reputation: 606

Post » Sun Sep 08, 2013 4:18 pm

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.
B
6
S
1
Posts: 76
Reputation: 606

Post » Mon Sep 09, 2013 11:09 am

[QUOTE=newt] 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&}}[/QUOTE]


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.
rogerfgay2013-09-09 11:12:39
B
6
S
1
Posts: 76
Reputation: 606

Post » Mon Sep 09, 2013 11:27 am

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.
Image ImageImage
B
172
S
50
G
184
Posts: 8,444
Reputation: 116,107

Post » Mon Sep 09, 2013 11:47 am

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.
B
6
S
1
Posts: 76
Reputation: 606

Post » Mon Sep 09, 2013 12:05 pm

[QUOTE=newt] 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.[/QUOTE]

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.
B
6
S
1
Posts: 76
Reputation: 606

PreviousNext

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 0 guests