Issue with editing a plugin

0 favourites
  • 8 posts
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Have you defined:

    Cnds.prototype.OnNetworkError= function ()

    {

    return true;

    };

  • Yes sir. Which is why i'm confused.

  • Can you show the entire function that is calling this?

  • 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:

    instanceProto.OnNetworkConnect = function (evt)
    if(evt.type === "Network Error"){
        console.log("Network error");
        this.runtime.trigger(cr.plugins_.WiiU_Private.prototype.cnds.OnNetworkError, this);
    }
    [/code:2ap13qfk]
    
    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:2ap13qfk]	Cnds.prototype.OnNetworkError = function ()
    	{
    		return true;
    	};
    [/code:2ap13qfk]
    
    I have also tried:
    
    [code:2ap13qfk]var self = this;
    self.runtime.trigger(cr.plugins_.WiiU_Private.prototype.cnds.OnNetworkError, self);[/code:2ap13qfk]
    
    ...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?
  • 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.

  • 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.

  • "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.

    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);
    }[/code:3inczl09]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)