Jump to content

Help with peace of code


Aurelijus
 Share

Recommended Posts

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""end

How can i convert them into php websocket functions?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...