For Each Conditions

This forum is currently in read-only mode.
  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • 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':

    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, [i]curDir = Files.GetAt(i);[/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).
  • read you loud and clear,

    the changes have been made and tested with subevents

    thanks as usual

  • EDIT

    nm, figured out the first two questions, but:

    what is the SelectF, and IsSelectedF for?

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

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