Iterate Through Instances

This forum is currently in read-only mode.
  • I swear, this is my last question for a while. Okay, now that I know how to set up a static vector for storing pointers to other objects with the behavior, I need to know how to iterate through the pointers in the vector and retrieve data. I know it involves something similar to this:

    for (i = sameBehavior.begin(); i != sameBehavior.end(); i++)
    {
    
    }[/code:h8yfsghd]
    But I don't know how to properly setup the iterator or retrieve data from the current instance.
    
    Sorry if this is more general C++ than SDK specific, but I can't seem to find what I need anywhere else.  Any help would be greatly appreciated.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Don't be afraid to ask questions - this is what the forum is for. Each question you ask gets answered and stays here, readable by everyone who decides to dabble with SDK. So, yeah, you're in fact helping form a FAQ

  • An iterator is defined as what it is you are iterating.

    vector<CRunObject*>::iterator i = sameBehavior.begin();

    Then continue as you were with the loop. Because you're iterating pointers, you access the data of the CRunObject like so: (*i)->.

  • Don't be afraid to ask questions - this is what the forum is for. Each question you ask gets answered and stays here, readable by everyone who decides to dabble with SDK. So, yeah, you're in fact helping form a FAQ

    Blah, you're probably right.

    An iterator is defined as what it is you are iterating.

    vector<CRunObject*>::iterator i = sameBehavior.begin();

    Then continue as you were with the loop. Because you're iterating pointers, you access the data of the CRunObject like so: (*i)->.

    Sweet! It works! I was doing something very similar to this before, but this actually worked.

  • Just thought I'd mention this for anybody else doing something similar to this. If you're making a behavior and want to share the properties of the objects they're linked to, you should use this:

    sameBehavior.push_back(pLink);[/code:ncps86ui]
    Not this:
    
    [code:ncps86ui]sameBehavior.push_back(this);[/code:ncps86ui]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)