Skip to content

Instantly share code, notes, and snippets.

@NakedMoleRatScientist
Created June 8, 2010 20:03
Show Gist options
  • Select an option

  • Save NakedMoleRatScientist/430573 to your computer and use it in GitHub Desktop.

Select an option

Save NakedMoleRatScientist/430573 to your computer and use it in GitHub Desktop.
function ScoreNetwork(score)
{
var self = this;
self.ws = null;
self.data = null;
self.score = score;
self.net = self;
self.initialize = function()
{
self.ws = new WebSocket('ws://localhost:7000');
self.ws.onmessage = function(event)
{
self.data = JSON.parse(event.data);
self.score.changeMinimum(self.getLimit());
}
self.ws.onclose = function()
{
console.log("Welcome to our world");
}
}
//Return the mininum score to submit score to database.
self.getLimit = function()
{
if (self.data.status == true)
{
return self.data.scores[99];
}
return false;
}
this.transmitScore = function()
{
var message = {
name = "kiba",
points = self.score.points,
};
data = JSON.parse(message);
self.ws.send(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment