How do I use messages from websocket server in construct 2?

Get help using Construct 2

Post » Tue Jun 27, 2017 6:03 am

I want to do:

websocket On message => if message: "login" or "other message from server" go to Layout xx1

Or how can I messages from server via websocket use to trigger events?

sorry for my bad english
B
3
S
1
Posts: 1
Reputation: 277

Post » Tue Jun 27, 2017 5:29 pm

Right now, I am running a WebSocket server for my game's chat.

I developed a message format for passing messages to and from the server using JSON, like:

{ “to” : [ name0, name1, ... ], “frm” : name, “msg” : message text, “snt” : sent timestamp }

Just today, I found myself having to expand this out to include chat room invite messages also, so my current message API looks like:

{ "type" : message_type, "uri" : chat_room_uri, "cm": { “to” : [ name0, name1, ... ], “frm” : name, “msg” : message text, “snt” : sent timestamp } }

With this new message format, I can allow users to send private chat room invites using the global chat as a messaging framework, like:
{"type":"invite","uri":"/chat/s9sub73hfkjk37","cm":{}}

In your case, you could use JSON like:

{"event":event_type,"layout":layout_to_go_to} or whatever. You can craft the JSON to fit your needs exactly, then parse it using @Yann 's JSON parser.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,418
Reputation: 4,830


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests