Use Function.Call from my plugin; how?

For developers using the Construct 2 Javascript SDK

Post » Mon Apr 29, 2013 3:46 pm

I like the worksheet plugin. It's a nifty timing based plugin. Good for scripting. That could actually work well in a turn based action parsing system. Thanks for the link.

B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Tue Apr 30, 2013 4:53 am

@jayderyu

The "(official) function" could be an unit of actions (included conditions), it is a good interface between external text script and C2 events. Worksheet is an example of text script.

My functionext plugin is another one, it could call "(official) function" in javascript. Designer could inject the javascript code into C2, to control the exection flow of events.
In this case, designer does not need to read (or find) a lot of api of each object (plugin), just need to know how to inject javascript function and how to call "(official) function" in these code.rexrainbow2013-04-30 06:23:26
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Tue Oct 11, 2016 5:27 pm

rexrainbow wrote:- Get function handler
Code: Select all
this._call_fn = cr.plugins_.Function.prototype.acts.CallFunction;

- Get "this"
Code: Select all
this._official_fnobj = plugin.instances[0];

- Call "on function"
Code: Select all
this._call_fn.call(this._official_fnobj, name, params);


Hi, I've got a problem with the second instruction:
Code: Select all
this._official_fnobj = plugin.instances[0];


I'm trying to do this inside of instanceProto.tick, and it reasonably says "plugin is not defined". How do I do this in my case?
B
7
S
1
Posts: 4
Reputation: 383

Post » Wed Oct 12, 2016 12:02 am

Now you can use

if (window["c2_callFunction"])
window["c2_callFunction"]("name", ["param1", "param2"]);

to call function in your plugin
Reference https://www.scirra.com/manual/149/function , "Javascript integration" section
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Wed Oct 12, 2016 12:48 am

rexrainbow wrote:Now you can use

if (window["c2_callFunction"])
window["c2_callFunction"]("name", ["param1", "param2"]);

to call function in your plugin
Reference https://www.scirra.com/manual/149/function , "Javascript integration" section


Thanks, that helped!
B
7
S
1
Posts: 4
Reputation: 383

Previous

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests