Calling event editor functions from JavaScript code

0 favourites
  • 4 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hello, everyone.

    I'd like to access a function from my plugin, not a JavaScript function but an event editor one.

    Before I start to implement the idea does someone know if it's possible?

    Thanks a lot!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Guys,

    I did it and I want to share the solution in case someone asks the same question in the future.

    I learned to do it by studying one of Rex.Rainbow's amazing extensions: "Command Queue"

    so the code is all his. I made some comments in the code to simplify the understanding for

    initiates.

    // Check if there is Function Object loaded in the project
    if (cr.plugins_.Function != null)    
    {
    	// Iterate through all names of the project's Object Types
    	for (name in this.runtime.types)
    	{
    		// We only want the first instance of the Function plugin, because
    		// there is only one in the project (plugin type is "object" not "world")
    		var inst = plugins[name].instances[0];
    		
    		// Check if we found the Function object's single instance
    		if (inst instanceof cr.plugins_.Function.prototype.Instance)
    		{
    			// Store the instance and the action in variables
    			// The instance will be passed to the CallFunction when we call it
    			this.functionObjInstance = inst;
    			this.functionCallFunction = cr.plugins_.Function.prototype.acts.CallFunction;
    			break;
    		}
    	}
    }
    [/code:116h5l8p]
    
    You can get the conditions and expressions as well. I'll only use the action "CallFunction" in my plugin.
    Then you can call the function stored in the variable.
    
    [code:116h5l8p]
    // Then later in our code we are able to call "CallFunction" and pass the instance as
    // the first parameter, the function name as the second and the parameter list as the
    // third parameter
    this.functionCallFunction.call(this.functionObjInstance, "fn_Example", "");
    [/code:116h5l8p]
    
    Thank you, rex, for your amazing extensions and for the code to be so easy to learn from.
    
    Best regards to all!
  • Javascript integration

    if (c2_callFunction)
        c2_callFunction("name", ["param1", "param2"]);[/code:37wfx15k]
  • rexrainbow: Thank you. Now I feel silly. I guess my effort was all in vain. Well, maybe not totally in vain because I learned a lot from your code and of javascript in general. [EDIT] I will RTFM before asking more questions. That's only fair. Thanks again for your enormous contribution.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)