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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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