Issue with editing a plugin

Post your work in progress addons and get feedback

Post » Fri Sep 12, 2014 11:10 pm

I have a system message that pops up on a users device, that uses a separate JS file, with a function built into one of the arguments.... like this; Dialog.displaySystemError(onUIDialogClose, error);

Once the user clicks the 'Close' button... it then calls my function "function onUIDialogClose(evt)" from within the same runtime.js file in my plugin. This function gets called just fine... however... when I try to get it to trigger an event inside this function like this:

self.runtime.trigger(cr.plugins_.MyPlugin_Private.prototype.cnds.OnNetworkError, self);

I get an error:

"TypeError: 'undefined' is not an object (evaluating 'self.runtime.trigger')"

I have val self = this;
Should I be doing more? I'm a bit lost.

Anyone know what I'm doing wrong? Thanks!
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Fri Sep 12, 2014 11:16 pm

Have you defined:
Cnds.prototype.OnNetworkError= function ()
{
return true;
};
ImageImageImage
B
71
S
21
G
233
Posts: 3,696
Reputation: 130,368

Post » Fri Sep 12, 2014 11:36 pm

Yes sir. Which is why i'm confused.
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Fri Sep 12, 2014 11:48 pm

Can you show the entire function that is calling this?
ImageImageImage
B
71
S
21
G
233
Posts: 3,696
Reputation: 130,368

Post » Sat Jan 24, 2015 8:22 pm

Anyone have any idea why this is happening? I've come back to this, and running into the same issue. I can't show the entire function, it's almost impossible. This is essentially what it looks like:

I've added a listener, to point to this function:

Code: Select all
instanceProto.OnNetworkConnect = function (evt)
if(evt.type === "Network Error"){
    console.log("Network error");
    this.runtime.trigger(cr.plugins_.WiiU_Private.prototype.cnds.OnNetworkError, this);
}


It displays the console log "Network error" and then goes on to say : Error: TypeError: 'undefined' is not an object (evaluating 'this.runtime.trigger')(0) thrown; Sorting... (0) from ()

And I already have this defined as well:

Code: Select all
   Cnds.prototype.OnNetworkError = function ()
   {
      return true;
   };


I have also tried:

Code: Select all
var self = this;
self.runtime.trigger(cr.plugins_.WiiU_Private.prototype.cnds.OnNetworkError, self);


...with no luck.

If I add a console.log, with the actual function (cr.plugins_.WiiU_Private.prototype.cnds.OnNetworkError) , it actually outputs the entire function in text... so it's not like it's undefined... for some reason, C2 isn't picking it up properly.

Anyone have any ideas?
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Sun Jan 25, 2015 8:02 am

Is the trigger function throwing the error? What does alert(this.runtime.trigger) give you?

Edit: you can call the function but since the calling function isn't part of the instance object, "this" isn't an instance so it doesn't have this.runtime.

If your object only ever has one instance you could add a global var that you set in your onCreate function to be "this", then you can use the var instead in your function.
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Tue Jan 27, 2015 5:14 am

R0J0hound wrote:Is the trigger function throwing the error? What does alert(this.runtime.trigger) give you?

Edit: you can call the function but since the calling function isn't part of the instance object, "this" isn't an instance so it doesn't have this.runtime.

If your object only ever has one instance you could add a global var that you set in your onCreate function to be "this", then you can use the var instead in your function.


@R0J0hound: Sorry about the wait... when I do the alert, I get this:

[ ] CONSOLE: TypeError: 'undefined' is not an object (evaluating 'this.runtime.trigger')
[ ] CONSOLE: Error: TypeError: 'undefined' is not an object (evaluating 'this.runtime.trigger')(0) thrown; Sorting... (0) from ()

So... same thing. :( And in my OnCreate, I have this : var self = this;

Yet, at times, I STILL need to remind it that self = this, cause it forgets throughout the project. But even then, it still doesn't work on this particular situation.
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Tue Jan 27, 2015 5:48 am

"this" is undefined in your code. Setting "self" to "this" doesn't change that in this case.

Read the "Function context" for the reason why:
https://developer.mozilla.org/en-US/doc ... ators/this

"close" is clicked and the then it calls onUIDialogClose() which in turn try's to call this.runtime.trigger().
But this is undefined since onUIDialogClose isn't called from an object.

Use the mouse plugin as an example. It sets up the callbacks from the onCreate function. That way the callback can know what self is.
Code: Select all
instanceProto.onCreate = function()
{
   var self = this;
   jQuery(document).mousemove(
      function(info) {
         self.onMouseMove(info);
      }
   );
}

instanceProto.onMouseMove(info)
{
   this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnAnyClick, this);
}
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971


Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 0 guests