For each?

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Thu Mar 11, 2010 7:01 pm

How would I implement a For each... -style condition in my object? SVN does not have examples on this, such as Array::For each element.

Is it just a matter of (pseudoish code):
[code:vo7952n6]
long ExtObject::cForEachThing(LPVAL params)
{
if(things.size() == 0)
return false; //no things, no for each

currentThing++;

//reset counter if at end
if(currentThing == things.end());
currentThing = things.begin();

return true;
}
[/code:vo7952n6]
and then an expression to retrieve data from currentThing. Doesn't this just get called once per frame, when I want to go through each object on every frame?
B
2
S
1
G
3
Posts: 71
Reputation: 1,142

Post » Fri Mar 12, 2010 2:24 am

You would have to loop through everything in that thing.

so you would have a loop

[code:f04cr8ii]
extObj::cMyfunction(lpval PARAMS)
{
for(int i =0; i < keys.length; i++)
{
currentKey = keys[i]
}

}

in your expression ace

extObj::eReturnCurrentKey(Lpval params)
{
return currentKey;
}

somthing like that I think would be how its done

[/code:f04cr8ii]
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Fri Mar 12, 2010 3:41 am

gotta go to bed, so I don't have time to distill the answer down, but here's a good start (especially ashley's part)
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Fri Mar 12, 2010 4:09 am

Lucid did you forget to post something along with that?
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Fri Mar 12, 2010 12:31 pm

oh yeah, oops:
[url:3n7amwuw]http://www.scirra.com/forum/viewtopic.php?f=7&t=4064&p=32406&hilit=loop[/url:3n7amwuw]
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Fri Mar 12, 2010 1:27 pm

Interesting, I wouldn't have ever figured that out on my own.
B
2
S
1
G
3
Posts: 71
Reputation: 1,142

Post » Fri Mar 12, 2010 6:33 pm

Yeah, Lucid's link has the right way to do it. You have to hijack the event system to repeat the event actions multiple times - if you don't do that the actions will only ever be run once!
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests