Jump to content

How to pass scope into inline function?


jjwallace
 Share

Recommended Posts

Uncaught ReferenceError: tempScope is not defined

creature[e].anim.onLoop.add(function(tempScope){
         console.log("Loops");
                                        
         console.log('animation complete');
         //creature[e].anim.remove();
         tempScope.loadTexture('organism'+tempScope.varType);
         //temp scope = this = creature[e] ??         
                                        
         tempScope.angle *= -1;
         tempScope.x = -1000;
         tempScope.y = tempScope.world.randomY;
         tempScope.varSpeed = Math.floor((Math.random() * 4) + 1);
                                        
}, this);

 

Link to comment
Share on other sites

`tempScope` is a parameter of the function, if this parameter is not passed to the function then its reference becomes undefined, if you try and operate on it then the runtime will throw an error.

Whatever `creature[e].anim.onLoop.add` is doing with the callback you supplied, it isnt passing anything to the function.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...