Array looping within an action plugin

For developers using the Construct 2 Javascript SDK

Post » Tue Feb 26, 2013 12:19 am

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

B
5
Posts: 39
Reputation: 678

Post » Tue Feb 26, 2013 12:25 am

@aceofpack

"For Each Element" is a kind of condition in array plugin, you could find it in runtime.js in array plugin.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Tue Feb 26, 2013 12:38 am

@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?
B
5
Posts: 39
Reputation: 678

Post » Tue Feb 26, 2013 12:42 am

@aceofpack

1. yes, 3rd plugin could have condition (event)
2. expression only accepts number or string.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Wed Feb 27, 2013 7:04 pm

@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!
B
5
Posts: 39
Reputation: 678

Post » Thu Feb 28, 2013 1:38 am

@aceofpack

It just re-triggers current event (condition). You could trace it by insert a "debugger" line.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Mar 01, 2013 9:56 pm

@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.
B
5
Posts: 39
Reputation: 678


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests