[PLUGIN] rex_Function2

  • For example of function plugin using in event sheet, it can be found at the first post of this thread.

    For example of injecting javascript, hum... I need some days to prepare, actually, it is not completed yet.

    Currently, I'm trying to make another plugin, to handle the game logic in javascript. Maybe it's more suitable then injecting javascript code in function.

  • I use this plugin - great work :)

  • Thanks.

    Function plugin is important for me, not only to save events, but also to save the time of making plugin by combining with other plugins like [behavior] timer, [plugin] timeline, [plugin] worksheet, and [plugin] sync-function.

  • Found a bug with this plugin. To reproduce it: Create three layouts. On layout2 add On Function "Foo1" -> Make Something like Set Text to "Foo1"

    then add On Start of Layout -> Call Foo1

    On Layout 3 add On Start of Layout -> Set Text to "Layout3". On Layout1 add reference to Layout 2 then Layout3

    Expected result when running : Text is "Layout3" .

    Current result: Text is "Foo1"

    That is, The call to Foo1 is preventing the execution of On Start of Layout for all other layouts after the layout where Foo1 executes.

  • Thanks.

    I trace this case, but I can not fix it. The error seems come from engine. I will report to

  • Update:

    Add "action: Inject JS function objects" for advance user. You can pass a code string. Plugin will use eval to parse it then execute it.

    Example

    The code string is

    function(fn)
    {
        var my_add = function(fn)
        {
            fn.result = fn.param[0] + fn.param[1];
            fn.CallFn('message', 'I\'m at js function');
        };
        fn.InjectJS('my_add', my_add);
    }

    1. This code string is a function with one input parameter named 'fn' which is a part of function plugin.

    2. Use command 'fn.InjectJS' to assign a js function into function plugin.

    In this example:

    fn.InjectJS('my_add', my_add);
    • User can use 'action:call "my_add"' in event sheet to execute this js function

    3. The 'my_add' function has a input parameter named "fn". It is the same as 'fn' at previous.

    • 'fn.param' is to get the value set by 'action: set parameter'
    • 'fn.result' is to set the value got by Function.Result.
    • 'fn.CallFn(name, param0, param1)' can call any function defined in this function plugin, even in event sheet. In this example, it will call 'message' which is defined at event sheet to append some text at text object. Oh, it can return the value set by 'action: set Result'.

    This feature can not let you control every objects in javascript. User can use javascript as game logic, and call 'fn.CallFn' to interact with other objects, or get some values from event sheet.

    The API of internal function object (using in JS) are listed below.

    A. set parameters, returns

    • fn.param

    :: input parameters, a hash

    • fn.ret

    :: return values ,a hash

    • fn.result

    :: return value, single value

    B. call function

    • fn.CallFn(name, param0, param1...)

    C. inject javascript function

    • fn.InjectJS(name, fn)

    Additional:

    When the name of javascript function is the same as the function defined in event sheet, the function plugin will execute javascript function first, then the event sheet one.

    If the javascript function return true, function plugin will not continue to execute the event sheet one. You can use this trick to do some checking/preprocessing before running the function defined in event sheet.

  • How safe is this? Would someone be able to hack the system using a method similar to an SQL injection in the game? For that matter, would this be able to hijack an AJAX call and send the player to a phishing/malware site? Just wondering, I'm not yet up on C2 security.

  • Would it let me call a piece of javascript with jquery, like this:

    $.post("https://www.scoreoid.com/api/getNotification", { api_key: "Your API Key", game_id: "Your Game ID", response: "JSON"},

       function(data) {

         alert("Data Loaded: " + data);

       },

    "json"

    );

  • dagda825

    I'm not yet up on C2 security, too.

    But I thought, if designer did not create a entry to allow player input string for code injecting, it might be safe.

    Designer just use this feature to create game logic.

  • smitchell

    Yes, you can call javascript with jquery in this feature, even you can call function defined in event sheet(Condition:On function) for a callback.

  • That's alright. I'm going to give the plugin a go; it looks fantastic! Thanks for coding it. <img src="smileys/smiley20.gif" border="0" align="middle" />

  • Im calling the javascript, But it doesn't like the syntax, More specifically the $, I think this is because i removed the "" but even when its there it doesn't like the script because there is various "" already in the code.

    $.post("https://www.scoreoid.com/api/getNotification", { api_key: "Your API Key", game_id: "Your Game ID", response: "JSON"},

       function(data) {

         alert("Data Loaded: " + data);

       },

    "json"

    );

  • If the problem is "" , try loading code string from AJAX plugin.

  • rexrainbow,

    ?? You think i should load the strings from ajax and the call the javascript? Will that work? could you show me a example..?

  • Try Construct 3

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

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

    I put an example in original zip file. See test_fn_js_inject_AJAX.capx,

    and an exported folder, the code string is put in file "fn.js".

    You can type the code string in C2 editor, or use AJAX to load from external file.

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