This is for a gameing application I declare the variable skipnpc which is designed as an indicator that a non player character has used his turn and any AI code related to his behavior is skipped for a period of time. the problem I have is I am loosing the value of skipnpc somehow I indicated where in the console.log commands I issue is related to varaible scope but I don't understand how to fix it.
function npcMovement() {
skipnpc = false;...
sql4 = "SELECT id FROM game_moblist WHERE spawn_id =" + spawnid + " AND posx=" + parseInt(mobpathx[mobpathx.length - 1]) + " AND posy=" + parseInt(mobpathy[mobpathy.length - 1])
connection.query(sql4, function (err, send, fields) {
console.log("skipnpc pathing")
io.sockets.emit('groupmoveresult', send, parseInt(mobpathx[mobpathx.length - 1]), parseInt(mobpathy[mobpathy.length - 1]))
skipnpc = true
console.log("skipnpc=true:" + skipnpc)
});
console.log("skipnpc = false:" + skipnpc)
Later I use
if (skipnpc==false){
...
before any further AI code is attempted