Im working on sensor code and when an object is it certain bounds it should emit('enterProximity') so when this code runs
main.js
var entered = require('./main').onProximityBoolean
io.on('connection', function(socket) {
setInterval(function() {
console.log("entered index " + entered);
var here = entered.onProximityBoolean;
if (here == true) {
socket.emit('enterProximity');
}
},1000);
}
In this code "here" should equal true when "enter" is true in main.js
enter = false
function onProximityBoolean(enter) {
console.log(enter + " emit entered");
return enter;
}
module.exports = {
withinBounds: withinBounds,
onProximityBoolean: onProximityBoolean(enter)
};
but instead it prints like this
https://i.sstatic.net/Yvh6U.jpg
how do i get here to reassign itself continously?
onProximityBooleanin module.exports withenterwhich from the code posted isundefined. Which assigns the keyonProximityBooleanwith a value false and it never changes.enteris never changing as you are not callingonProximityBooleaninsidesetInterval. Further More, sincemodule.exports = { withinBounds: withinBounds, onProximityBoolean: onProximityBoolean(enter) };has an assigned valuefalsefor the keyonProximityBoolean