Array looping within an action plugin

0 favourites
  • 7 posts
From the Asset Store
6 looping tracks to use in your games and projects. These tracks are in the style of the 1960s detective movie genre.
  • Hi all,

    I'm amending the socket.io plugin again and looking for some advice on actions:

    acts.ScriptName = function (params)

    {

    // do something

    };

    So I have an array called dataStack[].

    I'm pushing objects into it something like this:

    event = new instance.Event;

    event.name = blah; //String

    event.data = blah; //JSON

    event.time = Date.time(); //Time in ms

    dataStack.push(event);

    What I want to do is expose the looping through the array to C2.

    Something like a For Each Element action...

    How does this work and tie in with the loopIndex exposed to loops within C2?

    Many thanks for some pointers...

  • aceofpack

    "For Each Element" is a kind of condition in array plugin, you could find it in runtime.js in array plugin.

  • Try Construct 3

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

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

    Many thanks but I couldn't see it...then discovered it's an Event not an action. Are we able to write events?

    Failing that, I could do a LoadArray type expression? Although a bit confused about the arrays in C2, do they take objects?

  • aceofpack

    1. yes, 3rd plugin could have condition (event)

    2. expression only accepts number or string.

  • rexrainbow

    Many thanks for your speedy help!

    I found the function. It accepts a parameter 'dims' (dimension of array to loop through) and within those loops calls another function using:

    this.doForEachTrigger(current_event);

    Which is:

         instanceProto.doForEachTrigger = function (current_event)

         {

              this.runtime.pushCopySol(current_event.solModifiers);

              current_event.retrigger();

              this.runtime.popSol(current_event.solModifiers);

         };

    What do these 3 lines of code do? I see a push and pop but not sure where the code for these functions are.

    Thanks for any help as always!

  • aceofpack

    It just re-triggers current event (condition). You could trace it by insert a "debugger" line.

  • rexrainbow

    Thanks, I've updated the Socket IO plugin now to feature this event capturing and looping and works like a charm.

    Need to do some more testing with my example game and publish soon enough.

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