Two problems.
1 .: You defined lastbalanceas a function parameter ... that created another variable lastbalancein the context of your function ... that replaced the variable declared in the outer scope.
var lastbalance;
getBalance = function (lastbalance, callback) {
btcclient.getBalance('*', 0, function (err, balance) {
if (err) return console.log(err);
if (lastbalance != balance || typeof lastbalance == 'undefined') {
console.log('Last Balance:' + lastbalance);
var lastbalance = balance;
updateCauses();
}
console.log('Balance:', balance);
if (typeof callback == 'function') callback();
});
};
setInterval(getBalance, 2000, lastbalance);
2 .: You used varto declare another lastbalancein your function. Do not do this; this caused the problem described above.
var lastbalance;
getBalance = function (lastbalance, callback) {
btcclient.getBalance('*', 0, function (err, balance) {
if (err) return console.log(err);
if (lastbalance != balance || typeof lastbalance == 'undefined') {
console.log('Last Balance:' + lastbalance);
var lastbalance = balance;
updateCauses();
}
console.log('Balance:', balance);
if (typeof callback == 'function') callback();
});
};
setInterval(getBalance, 2000, lastbalance);
, :
var lastbalance;
getBalance = function (/*lastbalance, */callback) {
btcclient.getBalance('*', 0, function (err, balance) {
if (err) return console.log(err);
if (lastbalance != balance || typeof lastbalance == 'undefined') {
console.log('Last Balance:' + lastbalance);
lastbalance = balance;
updateCauses();
}
console.log('Balance:', balance);
if (typeof callback == 'function') callback();
});
};
setInterval(getBalance, 2000);