Use Function.Call from my plugin; how?

0 favourites
From the Asset Store
Voice call plugin based on webrtc protocol for construct 3
  • I'm tinkering with a plugin of course. What I'm wondering is how to do I effectively call

    Function.Call("foo", var, var)

    from my own plugin.

  • this._call_fn = cr.plugins_.Function.prototype.acts.CallFunction;
    this._official_fnobj = plugin.instances[0];, name, params);
  • I would advise against any sort of plugins-calling-other-plugins integration like this, because it's bad design. In general a plugin should be a self-contained unit of purpose, and not depend on or use any other plugins outside of itself.

  • Ashley

    It has some trade-off about choosing a self-contained or a dependency plugin.

    • plugin designer might create a new plugin(or behavior) copied from official plugin because that he/she want to add only one action into this official plugin.
    • A self-contained is easy to use for beginner. But user might need to learn the same interface once again at other plugin (or behavior).

    For example, user had already known how to use official function object, then user need to learn the same interface in 3rd plugin once again.

    • the plugin will become very large if it duplicate all of dependency and hard to maintain, more bugs.

    <img src="" border="0" />

    Here is my board plugin system. I agree that it has a learning gap for beginner. Each plugin has it's own job, user might learn a new plugin member easily when he/she already understand how to use the core plugin(board plugin).

    Dedicate condition/action/expression is more easy to read at some cases. In these case, I will chose to have a dedicate ACE.


    I thought a well-organization architecture is the most important thing. Easy to maintain, more readable, and more extend-able.

    A self-contained plugin might not be the best choice sometimes, imo.

  • I'm going to agree with Rex. The Function plugin is a fantastic extendible worthy plugin. Using C2 Function plugin as a callback form for users makes it easier for users to understand and integrate. Requiring to now create a version of Function in my own code means that my code is now larger and requires the other developers to not take advantage of already familiar official plugins.

    I get both sides of the argument. I've seen Plugins in others systems like jEdit that can have layers upon layers of dependants. Where the user may only want 1 plugin they end up installing 6/7.

    yet on the other hand it requires the developers of the plugin to write all the extra code that may already be developed. Increasing memory usage, chance of performance reduction.

    Rex makes a case for the whole. However, Function is not considered an optional aspect of programming. Function/Method/Subroutines are staple of software development and making the C2 Function plugin wrong to use seem a little strange. However, if that's the stance your going to stick too I'll work around.

    I suppose I can just copy/paste the Function plugin into a new plugin and build on top.

    I appreciate the replies. Thanks Rex, I'll try that out. Don't know if I will stick to it due to the fact that might break someday :P

  • jayderyu

    I would not use the official function plugin to be the callback for special purpose, except the callback is only a general purpose function call.

    A dedicate condition/action/expression is better, more read-able.

    For example, a callback to get a value from event sheet (a use defined value) triggered by plugin. It could be done by a (official) function call and (official) set return value. However, it is better to have a dedicate condition "on get value" and dedicate action "set value". More over, the parameters of this callback could be passed by dedicate expression:CurState (just an example).


    Event sheet.

    + Myplugin:on get value
        + Myplugin.CurState = 1 
            - Myplugin: set value to 3
        + else
            - Myplugin: set value to 0


    // condition: on get value
    this.curState = 3;
    this.value = 0;
    this.runtime.trigger(cr.plugins_.Myplugin.prototype.cnds.OnGetValue, this);
    // action: set value
    Acts.prototype.SetValue = function (value)
        this.value = value;
    // expression:CurState
    Exps.prototype.CurState = function (ret)
  • I do agree. I prefer a dedicated coded cnd. What I'm trying to create is a C2 event listener where the developer defines there own event's. The Event being named a string.

    I don't technically need to use Function, but I thought it would be far more elegant and appropriate to use an already established plugin. The alternative is a switch statement, which doesn't exist or a more bulky form


    • if EventName = "shoot" -> Function.Call("function0", data)
    • if Eventname = "move" -> Function.Call("function1", data)

    I had just thought I could get a way with

    On Start Layout

    -> CustomEvent.RegisterCallback("function0", "shoot")

    -> CustomEvent.RegisterCallback("function1", "move"

    getting a number isn't really needed for a callback purpose. The idea would be for data processing and triggering based on structured data. Ajax based turn games. where lists of turn actions. Having the option to get a Function to be triggered for the action type of a turn just makes some sense.


    Player, Action, Unit, Data

    0, Move, 6, [6,4]

    0, Shoot, 4, 20

    1, Cover, 9, object12


    Anyways, This was all about tinkering. As there is no official support I will probably just leave it to just tinkering :D

    Thanks for the info :)

  • jayderyu

    Uh, do you mean that your plugin is used to communicate to each other client by passing "function object (function name and parameters)"?

    I had made a similar plugin before, and I call these functions through rex_function plugin (the official function had not ready at that time).

    It is a case of using general purpose function, imo. (not to get the user defined value)

    For example, in event sheet.

    // Myplugin: action of passing "function object structure", 
    // send this structure (JSON format) to server
    	[li]Myplugin: call "run" (1, 3)[/li]
    // Myplugin receive this structure (JSON format) from server,
    // trigger the official function object
    + on function "run"
    + function.param(0) = 1

    Plugin users could define their own "function object structure", and the handler at event sheet.

  • jayderyu

    Here is an example (worksheet) of calling official function object at 3rd plugin. This worksheet plugin will call these official functions at specific delay time, so the input of this worksheet plugin is a string which defined the delay time, function name, parameters.

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

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

  • - Get function handler

    this._call_fn = cr.plugins_.Function.prototype.acts.CallFunction;[/code:2vuqn2xh]
    - Get "this"
    [code:2vuqn2xh]this._official_fnobj = plugin.instances[0];[/code:2vuqn2xh]
    - Call "on function"
    [code:2vuqn2xh], name, params);[/code:2vuqn2xh]

    Hi, I've got a problem with the second instruction:

    this._official_fnobj = plugin.instances[0];[/code:2vuqn2xh]
    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?
  • Now you can use

    if (window["c2_callFunction"])

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

    to call function in your plugin

    Reference , "Javascript integration" section

  • Now you can use

    if (window["c2_callFunction"])

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

    to call function in your plugin

    Reference , "Javascript integration" section

    Thanks, that helped!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry to dig up this topic but maybe you could help me.

    I try to call "c2_callFunction" from a javascript called from an html page, which calls itself the html page that contains my Construct app.

    For information, in Construct I do an Execute Javascript "window.parent.postMessage ({score: 0}, '*'); And it works but not mean to do it the other way.

    Anyone with an idea how to do it?

    Thank you

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