i have application , counting clicks on object client side, sending server
socket.emit('playerscore',score);
pushing array server side
socket.on('playerscore',function(data){ socket.score = data; score.push(socket.score);
then sending clients
io.sockets.emit ('scores',score);
but receives score once each client, , sends clients once each client. trying compare score sent client on server side , send highest number compare local score client has. i'm sending more once , filter doesn't seem work.
var scoredata = data; var largest = scoredata[0]; (var = 0; < score.length; i++) { if (largest < scoredata[i] ) { largest = scoredata[i]; } }
thank
i think should pass highest score (from server client) instead of entire array. highest score, client can check if has stored locally.
but maybe have better approach this:
your array have:
{ socketid: '123123', score: 12 }
when server receives score, push score , socketid
get object array highest score
pass clients
with this, client-side compare direcly id, instead of score.
Comments
Post a Comment