Extending Construct 2 with Javascript

0 favourites
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Is it not working? I thought I coded support for that!

  • Is it not working? I thought I coded support for that!

    Actually, I was asking how to if there was. There aren't any plugins that I know of currently that use it, and I'm mostly learning everything through studying other plugins.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The HTML5 exporter in Construct 2 includes Google's V8 Javascript engine. This means both the editor and runtime parts of plugins can be written in javascript. This makes it much, much easier to extend Construct - previously you had to have relatively good knowledge of C++, which is a difficult language to learn

    I think C++ is easier than Javascript

  • To have parameters in plugin actions, conditions or expressions, call these before the related AddAction(), AddCondition() or AddExpression():

    // 0 is default initial value
    AddNumberParam("My param", "My description", "0");
    
    // can pass optional default as 3rd param
    AddStringParam("My param", "My description");
    
    // accepts either string or number
    AddAnyTypeParam("My param", "My description");
    
    // comparison combo box (equal, less than etc)
    AddCmpParam("My param", "My description");
    
    // object picker
    AddObjectParam("My param", "My description");[/code:1e1nua85]
    
    You can do combo params like this:
    [code:1e1nua85]AddComboParamOption("Foo");
    AddComboParamOption("Bar");
    AddComboParam("My param", "My description", 0); // 0 is default selection[/code:1e1nua85]
    
    These are the same for all of actions, conditions and expressions, except expressions can only take number, string or "anytype" params.
    
    Example:
    
    [code:1e1nua85]AddNumberParam("Number", "Enter a number, whoop de doo.");
    AddExpression(0, ef_return_number, "My expression", "My category", "MyExpression", "A description for my expression.");[/code:1e1nua85]
    
    As with actions and conditions, expressions retrieve their parameters by ordinary javascript parameters, but [i]following the required 'ret' parameter[/i].  For example, the above expression function would look like this:
    
    [code:1e1nua85]// You can choose any name for the "my_number" parameter, it doesn't matter.
    // However it must come *after* the "ret" parameter.
    exps["MyExpression"] = function (ret, my_number)
    	{
    		ret.set_float(my_number * 2); // just return parameter doubled
    	};[/code:1e1nua85]
    
    Hope that helps.  I'd recommend reading through the javascript of all the other plugins to gain an understanding of the SDK right now - there aren't any docs yet.
  • Ashley how are the Params stored and passed to the functions. Im trying to make a reference object that allows the user to store a reference to an object and then call actions based on an event, but I dont know how to call the function with the parameters. In the old version of construct they were all passed by sending in a vector or an array I think but now you use normal function parameters and im not sure how you store them when you are adding them in the ACES.

    and before you go telling me that there would be problems with calling functions like that i am well aware of them. If a user calls a function that does not exist the plugin would handle it.

  • I'm not sure what you mean... parameters are passed to the functions as ordinary javascript parameters now - if you have an integer parameter followed by a string parameter, it calls the action routine with a number followed by a string. These are just ordinary javascript values, nothing special.

  • ok so the way I want the object to work would be kinda like the function object where the user would call an add param action and then once all of the params have been added they would call a doAction event and the plugin would try to call the function. The problem I run into is passing the parameters. Because In the add param action the param would be added into an array but the functions no longer take arrays as parameters how do you pass each element of the array to the function separately when there is no defined number of parameters? Do you know if javascript has any kind of reflection?

  • apply (the function the runtime uses to do the same thing).

  • Extract from editime.js

    AddStringParam("\"data\"", "Data to encode", "\"\"");
    AddExpression(0, ef_return_string, "Encode MD5 (Hexa)", "Encoding", "encodeMD5", "Encodes the data provided with MD5 algorithm. Hexadecimal output.");
    AddStringParam("\"data\"", "Data to encode", "\"\"");
    AddExpression(1, ef_return_string, "Encode MD5 (Base64)", "Encoding", "encodeMD5B", "Encodes the data provided with MD5 algorithm. Base64 output.");

    I think there is an error in the way the sdk is using the parameters of the function AddExpression.

    AddExpression(0, ef_return_string, "Encode MD5 (Hexa)", "Encoding", "encodeMD5", "Encodes the data provided with MD5 algorithm. Hexadecimal output.");

    0 : First param _ ExpressionId

    ef_return_string : Flag

    "Encode MD5 (Base64)" : Supposed string to be used as "name" of the expression in the ACE Table

    "Encoding" : Group

    "encodeMD5" : Referal name string in runtime (related expression will be found using this string). String to appear in events too.

    "Encodes the data provided with MD5 algorithm. Hexadecimal output." : Explanation/comment in the ACE table.

    So the error is in the fact that "encodeMD5" is used as expression name in the ACE table. Supposed name is not used at all seemingly.

    Maybe I made a mistake in the understanding of this function. Please correct me if so.

  • Expression names are ignored right now. I was going to have them listed in the object panel, but opted for the actual expression text itself. It's worth having names anyway - I might use them for some other part of the UI in future.

  • Is python going to be supported in C2? Or is it only JS because of HTML5

  • Just javascript.

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