Toddler's Recent Forum Activity

  • valerypopoff, do you think there is a way to say for example, create a class on the *.js side and then make every instance of a sprite have an instance of that class ?

    Think of it as polymorphism, your "extends" so to speak.

  • File accepted.

  • Try Construct 3

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

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

    To access Javascript Variable:

    JS.Value("global_variable")

    JS.JSCodeValue("global_variable")

    Both does the same thing, so...why ?

  • Updated.

  • Link removed.

  • JS: Call function:

    Expression: "global_variable_function"

    Result:

    ValerypopoffJS plugin: Error in 'Call' action

    ---------------------

    JS code: global_variable_function()

    ---------------------

    final.end is undefined

  • With that sample javascript file, I tried Browser Log:

    JS.JSCodeValue("global_variable")

    and I got:

    ValerypopoffJS plugin: Error in 'JSCodeValue' expression

    ---------------------

    JS code: global_variable

    ---------------------

    global_variable is not defined

    Then I tried Browser Log:

    JS.Value("global_variable")

    And there is no error...instead...I got....0 !

  • It doesn't work:

    Sample Javascript file:

    var global_variable = "Global Variable's value.";

    function global_variable_function()

    {

    console.log("global variable function called");

    }

    var global_object = new class_object();

    class class_object

    {

    constructor()

    {

    this.name = "Kenny";

    this.age = 23;

    }

    internal_class_function()

    {

    console.log("Internal class function called.");

    }

    }

  • Thank you for your respond valerypopoff .

    I will be re-writing my educational notes to incorporate your plugin so any changes at this point is actually detrimental to my current momentum.

    However since you are open to request, may I request this:

    JS.VariableValue()

    With this, one will be able to JS.VariableValue("top_level_variable") to retrieve "Hello, I am top level variable".

    one will also be able to JS.VariableValue("newCharacter.age") to retrieve 23.

    This is straight forward, direct and just plain makes sense.

    ========================================================================

    Example *.js File:

    var top_level_variable = "Hello, I am top level variable".

    var newCharacter = new main_character();

    class main_character

    {

    constructor()

    {

    this.name = "Kenny";

    this.age = "23";

    this.number_of_death = 45;

    }

    some_internal_function_whatever_doesnt_matter()

    {

    }

    }

    ========================================================================

    without this method, currently users have to:

    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.top_level_variable").

    Accessing Object's value is the same: JS.AliasValue("Global.newCharacter.age")

    You see how this one new feature will run circles around the current "alias" nonsense ?

  • Hi valerypopoff,

    I see your view, I also notice you often execute the quote "You are doing it wrong" followed by put down speeches questioning the capability of the questioner when you were simply nicely asked a question.

    Not asking you to remove your love of using alias, just asking for a rather consistent outlet, you did not ask for functions to be alias didn't you ? And yet it is possible to have functions within functions in JavaScript, you knew how silly it will be if you were to implement alias to functions, but you insist on not having a non alias way of accessing variable data.

    I can understand that you are thinking your script will only hold objects and functions and some kind of a punishment is given [via your silly alias nonsense] if one decides to have top level variables in the js files, but can you imagine how ridiculous it is to explicitly declare all top level variables in Construct 2 though?

    You will have variables not used by anything in Construct 2 whose sole existence is to have the objects and functions in the js files interact with it, it is much preferable to have these variables tucked clean and neat inside the js file itself.

    It's ok, I see no resolution to this the same way I see that you are utterly insistent on "All scripts loaded" being by default a continuous trigger [which makes no sense to anyone besides you] and yet knowing that by your own logic, construct 2's internal "On loader layout complete" would be a continuous loop which of course, would be utterly retarded if it was so.

    I think you are doing some mental gymnastic compartmentalization here.

    However, it is a fact that despite these two flaws [yes yes I am doing it wrong because you are right I got it] your plugin is truly powerful.

    So I will use it as it is and appreciate the gift you have given the Construct 2 community :D

    Thank you valerypopoff .

    I really do wish you well because me and my students is going to benefit from this amazing work of yours.

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

  • Usage:

    Select the JS plugin, inside the script files section, enter the script files, example: script1.js;script2.js

    Import all the *.js files into the "Files" folder.

    Call JS function:

    Allows you to call a function from the js file.

    You can even call object functions like this: object1.function1.

    Return value can be accessed via JS.StoredReturnValue.

    Since StoredReturnValue contains only string, use JSON to transfer your data.

    To access a variable from a javascript file, you have to "Init alias" to set an alias for the variable.

    and then you can: js.AliasValue("enter the alias name here").

    Can we skip this step and straight away access the variable directly ?

    Like instead of js.AliasValue("enter the alias name here")

    we can just have js.variable_value("enter variable name here").

    So all in all I have three questions summarized:

    Question 1: Why is "All scripts loaded" continuously triggering ?

    It should trigger once when all the script is loaded and never trigger again ever.

    You don't see construct 2's On loader layout complete continuously triggering, it trigger once and stop.

    Question 2: Can we have js.variable_value("enter variable name here") instead of js.AliasValue("enter the alias name here") ?

    It's more direct, the alias just adds unnecessary levels of convolution.

    Question 3: Now this is difficult I think...can you somehow create a way for the custom javascript to have its own triggers ?

Toddler's avatar

Toddler

Member since 19 Jan, 2012

Twitter
Toddler has 1 followers

Trophy Case

  • 12-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Email Verified

Progress

14/44
How to earn trophies