I've got a function taking in some parameters, and I would like to assign the parameter to a value in an if statement. However, the value i'm assigning is different in other parts of the function. I'm sure this is due to scope, but i don't know how to fix it.
this.img = function(sx, sy, img, sw, sh, dx, dy, dw, dh) {
sw = 0;
sh = 0;
image.addEventListener('load', function() {
if(found) {
sw = this.width;
sh = this.height;
console.log(sw + ' ' + sh);
}
})
console.log(sw + ' ' + sh);
}
Just so you know, the "if(found)" is being entered(i'm changing the boolean elsewhere). The first console.log is returning the proper values, 225, 225. However the second one returns 0, 0.
If anyone knows whats wrong with my scope here, that would be great.