Calling C2 function from plugin

0 favourites
  • 9 posts
From the Asset Store
Medeival & Viking War Horns Sounds / 22 Unique Calls / 2:40 minutes of audio
  • Hi,

    Is it possible to program a plugin so that it gets the name of a C2 function passed, and then calls that function, including passing of parameters to the function and retrieving return values?

    If so, is there documentation or examples how to do this?

    thanks,

    Dan

  • I just noticed that Function is actually a plugin.

    So, it should be possible to retrieve all relevant function plugin instance data from another plugin, and thereby refer and also call functions ....

  • Here's a snippet to look at:

    Acts.prototype.SequencerAddSynchronizer = function (callbackName)

    {

    assert2(cr.plugins_.Function != null, "The 'BHT Step Sequencer' plugin requires the 'Function' plugin.");

    // Check that the Function plugin exists.

    if (cr.plugins_.Function != null)

    {

    var callFnc = cr.plugins_.Function.prototype.acts.CallFunction;

    var name, plugin;

    var runtimeTypes = thisInstance.runtime.types;

    for (name in runtimeTypes)

    {

    plugin = runtimeTypes[name];

    if (plugin.plugin.acts.CallFunction == callFnc)

    {

    this.Official_fnobj = plugin.instances[0];

    }

    }

    }

    this.CallbackSynchronizer = callbackName;

    }

    Acts.prototype.SequencerRemoveSynchronizer = function (callbackName)

    {

    this.CallbackSynchronizer = null;

    }

    Acts.prototype.SequencerClear = function ()

    {

    this.Stop();

    this.Clear();

    if (this.CallbackSynchronizer != null)

    {

    var params = [-1, -1, ""];

    cr.plugins_.Function.prototype.acts.CallFunction.call(this.Official_fnobj, this.CallbackSynchronizer, params);

    var fake_ret = {value:0,

    set_any: function(value){this.value=value;},

    set_int: function(value){this.value=value;},

    set_float: function(value){this.value=value;},

    set_string: function(value){this.value=value;},

    };

    cr.plugins_.Function.prototype.exps.ReturnValue.call(this.Official_fnobj, fake_ret);

    console.log(fake_ret);

    }

    }

  • Of course, see the manual of function plugin, "Javascript integration" section.

  • Thanks Rex,

    what I am thinking about is to create support a simple MapReduce function: https://code.google.com/p/mapreduce-js/

    With the C2 functions passed as parameters.

    I wonder if this can be done. Perhaps its already doable with your javascript function plugin

    Dan

  • grossd

    I guess it had not be made yet in this forums.

  • Rex,

    It now occurred to me that it should be pretty easy to rewrite the short MapReduce algorithm with C2. C2 has the ability to pass functions to function, as strings, and have the called. So, beside the neat packaging as a plugin, there seems no need to actually write a plugin for that. A separate event sheet should suffice.

    Dan

  • grossd

    It depends on you.

    In my point of view, "MapReduce" might not be easy to understand or to be used in real cases for normal users.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Perhaps you are right,

    In my case I have a following structure (All are dictionaries, and "varying game section" stats an Array, say, someone drops something X times during a game section, and i capture when (in seconds since game section start) each drop happened):

    User-Groups->Users->UserGamePlayedDate-Time>TotalGameStats->GameSectionsStats->VaryingGameSectionStats

    I need to analyze this data from various perspectives, such as improvements over time of individual users; average comparisons between user goups, etc. and graph it using charts (I am using the canvas chart plugin).

    Programming everything individually with loops can be pretty tedious. I am hoping that a map reduce implementation will make the code shorter and simpler.

    Dan

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