Thank you so much valerypopoff !
This is a truly powerful plugin.
I have updated the core docs for my students and will be updating the curriculum to include this plugin of yours.
Your resulting work is a very very powerful plugin and is going to change a lot of my C2 lessons to come as the complexity of projects can now include heavy duty object orientated programming concepts, these are the core Docs for your plugin to be included in my notes, hope it will help others here, I apologize that it can be a little too straight forward but as a teacher I know what my students will ask and be confused about so I rather lay it out in the notes:
This is a powerful plugin that allows full utilization of JavaScript in Construct 2 !
Step 1: Place plugin into your project & rename it to "JS" for convenience.
Step 2: Import file *.js files (as many as you like) into construct 2's "Files" folder.
Step 3: Select JS plugin & enter the file name(s) e.g. "src1.js;src2.js" into the script files section.
Now you can start to use it !
Only start using it when "All scripts loaded" is triggered.
For some stubborn reason, the creator choose to make it so that this event triggers continuously.
His reason is "because all scripts are indeed loaded and hence will always be true, always triggering."
That would be like saying the "On loader layout complete" event is indeed completed and hence will always be triggering, common sense will tell you such events should only trigger once.
Because of this pure stubbornness on the creator's side, please add in the "Trigger once" event to the "All scripts loaded" event so that it finally makes sense.
Accessing Global or Object Function (with or without return data):
Under Action, choose "Call JS function (stores return value)", enter function name inside example "function_name", for object just do "object1.function_name".
Return values is contained in: JS.StoredReturnValue.
Accessing Global or Object Variable:
This is another point of stubbornness from the creator, you have to create some silly "alias" nonsense that will be treated as the variable and access it using the alias.
Instead of allowing direct access just like the way functions are accessed [see top, notice you don't require an alias to access a function which actually makes sense],
the creator's stubbornness insist on the alias nonsense, his round about solution to this nonsense is:
Step 1: update your *.js file to include this: var _window = window;
Step 2: Right after "All scripts loaded" is triggered, put in JS action "Init alias", set top textbox to "Global" and bottom textbox to "_window".
Step 3: Now you can FINALLY access your global variables via: JS.AliasValue("Global.global_variable"). //Global.whatever_global_variable_name_you_choose.
Accessing Object's value is the same: JS.AliasValue("Global.object1.name")
Creating your own trigger:
This is single handedly the most powerful feature of the plugin.
To be honest, it doesn't "actually" create a custom trigger but merely calls a function set within Construct 2,
but this is enough, it is all your need for back and forth communication and triggering.
First, implement the following code into your *.js file:
function execute_construct_function(function_name, args)
{
if (function_name == "")
{
return;
}
args = (args === undefined) ? [] : args;
if ( c2_callFunction !== undefined )
{
return c2_callFunction(function_name, args);
}
}
Now all you have to do in your JavaScript is call:
execute_construct_function("Trigger"); //Assuming you have a Construct 2 function called "Trigger"
and it will work ! AMAZING ! This officially make this plugin the most powerful and flexible plugin in all of Construct 2's plugin history !