Aurelijus Posted December 19, 2015 Share Posted December 19, 2015 I want to create simple multyplayer game, other guy in video used this in his websocket function onMessage ( $uid, $msg)t = json.decode ($msg);t.id = 2t.uid = uidj = json.encode ( t )broadcast ( uid, j)return""endfunction onConnect ( uid )t = {}t.id = 1t.uid = uidj = json.encode ( t )broadcast ( uid,j)return""endHow can i convert them into php websocket functions? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted December 24, 2015 Share Posted December 24, 2015 Firstly there is nothing simple about a multiplayer game. Secondly, and I dont mean to sound harsh, but that code does almost nothing, if you cant work out what it does then you're going to have to start smaller because you need to do a hefty amount of learning. All that code tries to do is take an incoming message, append an id and then broadcast to all (other?) listeners. Their implementation expects JSON (websockets are just http, as such, they support other formats), converts it to an object, appends the id and converts it back into JSON to for the broadcast. Each message gets its own id for some reason, and the `onMessage` function gets a mysterious `uid` from somewhere but expects 2 parameters. It doesnt look like a good thing to copy at all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.