PlayerTracker.js:
var util = require('util');
var PlayerTracker = function(GameServer, pos) {
this.gs = GameServer;
this.pos = pos;
this.left = false;
this.right = false;
console.log("constructor" + util.inspect(this));
};
PlayerTracker.prototype.getPos = function() {
return this.pos;
};
PlayerTracker.prototype.setPos = function() {
return this.pos;
};
PlayerTracker.prototype.setLeft = function(left) {
this.left = left;
};
PlayerTracker.prototype.setRight = function(left) {
this.right = left;
};
PlayerTracker.prototype.moveTick = function() {
console.log(util.inspect(this));
if (this.left) {
if (this.pos <= 0) {
} else {
this.pos--;
this.left = false;
}
} else if (this.right) {
if (this.pos >= 10) {
} else {
this.pos++;
this.right = false;
}
}
};
module.exports = PlayerTracker;
At the Start i get:
constructor{ gs:
{ config: { serverPort: 1010, testValue: 0 },
socketServer:
{ domain: null,
_events: [Object],
_maxListeners: undefined,
_server: [Object],
_closeServer: [Function],
options: [Object],
path: null,
clients: [Object] } },
pos: 5,
left: false,
right: false }
but then after i call MoveTick, i get:
{ _idleTimeout: 500,
_idlePrev: null,
_idleNext: null,
_idleStart: 4060813,
_onTimeout: [Function: wrapper],
_repeat: true }
It looks like the this varibale resets.
I simply open it with var playerTracker = new PlayerTracker(this,5)
and call it with setInterval(playerTracker.moveTick,500)
I just want to keep the position and so on.
Do you know any reasons?