0 Favourites

A question about picking

This forum is currently in read-only mode.
  • Hello,

    I still seem to get a bit confused about some of Construct's inner workings. Maybe you guys can help me out a bit.

    I have a family "Ships". I want to pick all ships that have their private variable "status" set to "Engaged" and then run several checks and actions on them.

    Does it work like this?

    Pick Ships by comparison: Ships('status') = "Engaged"
      Move to Enemy...
    [/code:l4jytlz0]
    
    or do I have to do it like this:
    
    [code:l4jytlz0]
    Pick Ships by comparison: Ships('status') = "Engaged"
      For each Ships
        Move to Enemy...
    [/code:l4jytlz0]
    
    Meaning: When I "Pick object by comparison", does it loop through all objects picked automatically within that event, or do I have to do the "For each object" to loop through them?
    And: Does the For each then loop through all the Ships, or just the ones I filtered through picking in the parent event?
  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You don't need to use "Pick by comparison" in this case because there is a built-in expression for private variables. Just do like this:

    + Family.Ships: Value 'status' Equal to "Engaged"
        -> Do stuff
    [/code:3ns3kf75]
    
    You get that just by selecting the Ships family in the New Condition window and picking "Compare a private variable."  It's even hilighted in yellow.
    
    And no, there is no need for a loop.  The action will be performed on every member of the Ship family that meets the criteria in the condition.
  • Ah, thanks. That's awesome

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