This is my first post on the forum so please be kind.
The following is my code:
var powerValue = 0;
for(let l = 0; l < array.length; l++) {
let path = pathfind.findPath(coordX, coordY, powerSourceIndex[l][0], powerSourceIndex[l][1], function(path) {
if(path !== null) {
powerValue = 1;
console.log("set value = " + powerValue)
}
});
pathfind.calculate();
console.log("second read = " + powerValue)
}
I know that powerValue is indeed being set to 1, because I see the "set value = 1" on my console. However, I also see "second read = 0"
I am aware that similar issues have already been asked, but alot of these seem to be regarding asynchronous functions. Similar to an async, this function seems to have some kind of separated scope, but it isn't exactly an async.
I have done the research, believe me, I tried! But due to my lack of understanding of this specific issue, I can't seem to find a solution the problem.
Any help would be appreciated!
TLDR: I know powerValue is being set to 1 due to my console logging, but it is 0 at "second read"