Last active
August 29, 2015 14:28
-
-
Save itsjoekent/e54e481d8e362a49c5cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('update-pos', function(data) { | |
if(allMonsters[data.id] == undefined) { | |
allMonsters[data.id] = new Monster(data.x, data.y, data.type, data.id, data.direction); | |
} | |
else { | |
// Relevant part, by getting to this point we assume the human | |
// does in fact exist, as it's in the list of human ID's | |
posUpdates.push(data); | |
} | |
}); | |
Game.update = function() { | |
... | |
posUpdates.forEach(function(element, index, array) { | |
var theMonster = allMonsters[element.id]; | |
// Due to the previous test, we assumed that the monster here exists, | |
// however it disconnected before this function had an opritunuty to run and it's now undefined | |
// this causes and error and the client to fail | |
theMonster.x = element.x; | |
theMonster.y = element.y; | |
theMonster.animations.currentAnimation = 'move'; | |
theMonster.direction = element.direction; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment