I have a probably really simple problem, but I can't figure it out. I'll post some cut snippets of the code that doesn't work for some reason:
//authentication_handler.js
var new_user = server.authenticated_users.add_user(new User(world));
//user.js
function User(world) {
personBody = createPlayerBody(100, 100, 8, 8, false, true, world);
exports.TheBody = personBody;
}
//player_data_handler.js
module.exports = function(server, client) {
var theUser = server.authenticated_users.find_user(client.uuid);
if (theUser != null) {
var playerData = JSON.stringify({
x: theUser.TheBody.position.x, //this line throws the error below
y: theUser.TheBody.position.y
});
server.authenticated_users.each_other(theUser, function(user) {
server.send_id_message(user.client, 5, playerData);
});
}
};
The error I get is this:
Cannot read property 'position' of undefined
I'm still pretty new to JavaScript and I don't know why the "personBody" variable doesn't get passed all the way to the "player_data_handler.js". I've tried more approaches but none of them worked. Any help is very much appreciated!!