For Each Conditions

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

Post » Sun Jun 28, 2009 7:38 pm

how can you make a looping condition

if my plugin has a vector of Object Pointers:
vector<CRunObject*> Objects

already filled with the needed instance pointers

and basically like the system:: for each object condition
it loops through each object in this array
but there is internal information inside the plugin that is needed for specific index values so the system condition can't be used

I tried dissecting the sprite :: on collision condition,
and I can't tell what's necessary for this purpose, and what's there solely for the unique circumstances of collision detection

can I see a simple example of how to create a looping condition that picks one object per iteration?
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Jun 28, 2009 9:22 pm

ok, I got this to work:
SpriteString is a vector with pointers to each sprite object which is standing in for a character in the written phrase (bitmapped text object)
so ACE would be three sprite, one for each letter
in that order, in the vector
ForEachLoopIndex (//long name I know)is just an int, used for the loop index which the entire object has access to

long ExtObject::cForEachLetterInPhrase(LPVAL params)
{
EventParametersInfo2 epi;
pRuntime->GetCurrentEventPtrs(epi);
for(ForEachLoopIndex=0;ForEachLoopIndex<CurrentPhrase.GetLength();ForEachLoopIndex++)
{
pRuntime->SelectAll(FontSprite);
pRuntime->Select(SpriteString[ForEachLoopIndex]);
pRuntime->RunActions(epi.pActs);
}
return false;
}

is there anything I'm missing here that will break stuff down the line if I don't add it, and people start using this for more elaborate purposes?
I also specified SOL_MODIFIER in the ACE
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Jun 28, 2009 11:17 pm

You're missing lots of stuff, and you might cause problems in the event engine if you don't do it properly. Here's a snippet of how the File object does 'for each directory':

[code:3da8vbc0]long ExtObject::cForEachDirectory(LPVAL theParams)
{
CDiskObject Obj;
CStringArray Files;
Obj.EnumDirectories(GetStringParam(theParams, 0), Files);

EventParametersInfo2 epi;
pRuntime->GetCurrentEventPtrs(epi);

for (int i = 0; i < Files.GetSize(); i++) {

curDir = Files.GetAt(i);

pRuntime->NewSOLCopy();

if (epi.pCnds && !pRuntime->RunConditions(epi.pCnds)) {
pRuntime->RestoreSOL();
break;
}

if (epi.pActs)
pRuntime->RunActions(epi.pActs);

if (epi.pSubEvents)
pRuntime->RunSubEvents(epi.pSubEvents);

pRuntime->RestoreSOL();
}

return false;
}[/code:3da8vbc0]

You have to do all of the loop contents there - they all take care of some important apsect of picking and running events, so you can't skip any of it. Except, of course, curDir = Files.GetAt(i); is simply there so the file object knows the current directory to retrieve in expressions.

It's pretty complicated, but basically you'll notice the condition returns false, meaning the event runner in Construct stops running the event. Instead, the code in that loop essentially hijacks the event runner, running the event actions and subevents manually, in a loop. It works recursively so it works with two looping conditions in one event.

If you want to pick a particular object in an iteration, after the call to NewSOLCopy(), do your SelectAll() followed by Select() (and, of course, set the SOL_MODIFIER flag).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,590

Post » Sun Jun 28, 2009 11:43 pm

read you loud and clear,
the changes have been made and tested with subevents

thanks as usual
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sat Jul 04, 2009 3:17 pm

EDIT
nm, figured out the first two questions, but:

what is the SelectF, and IsSelectedF for?
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Jul 05, 2009 6:27 pm

Ah, use the ones with the F in the name (SelectF etc) instead of the other functions, at all times. They support families. The other functions should be deprecated.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,590


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests