Looping through multiple object types

This forum is currently in read-only mode.
From the Asset Store
6 looping tracks to use in your games and projects. These tracks are in the style of the 1960s detective movie genre.
  • Is there any way to do actions based on an object ID versus an object type? It seems strange that there are all these ways using "for each" and the like to loop using things like the solid attribute or object ID but you cannot actually do anything to the objects in these types of sets. This would be useful for doing the same actions to a few different types of objects without copying and pasting a bunch of code.. kind of like inheritance?

    Am I just missing something? Or maybe there's a way to work around this that I haven't thought of?


  • i don't know if i really understand your intention, but:

    if you want to loop through more than one object type, you could use families (wiki link).

    if you want to do things only to specific instances of an object type, you could use the 'Pick by evaluate' condition and use e.g. a private variable (or any other distinctive property) to pick the instances you need.

    if i missed what you were talking about, feel free to say so :)

  • Awesome, just what I was looking for! Thanks!

    One problem with this, though: If you want this to be run for each new object created, it doesn't let you create a certain type of object and then have the function that deals with the family as a whole still only work with that one new object. It would let you do this if the function just dealt with one object type, so it's strange that you can't do this with families unless you want a random object from that family to be created each time. I'm pretty sure this is just how the object picker thing works, but it's still pretty weird.

    I suppose you can create a variable and loop through them all looking for objects with that variable set to 0 or something, but that's kind of a weird way to do something like this.. (An On Create event or something would be pretty nice and solve quite a few problems like this, I think.)

  • I don't quite understand what you're saying. But if you're about to make event create the same object, as it was picked from family, then you can do this trick:

    1. Add to every object from family a Private Variable (name it for example "thisObjectName") - make it have a string.

    2. For every type of sprites give this PV a name of objects name. So if you have in family objects like:




    Populate their "thisObjectName" PV with:

    "SpriteA" for SpriteA object

    "SpriteB" for SpriteB object

    "SpriteC" for SpriteC object and so on

    When family object is selected by an event in event sheet, you can make use of System's action: "Create Object By Name". This one doesn't need you to select object from list, you just can order it creating an object with string you store in "thisObjectName" private variable.

    If your family is "green" then you write green('thisObjectName') to return its PV value.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here, I attached a cap of what I mean.

    Basically, the function should affect objects from that family and make them flash. Left click makes a new green object and calls the function, which makes them all flash. Right click makes a new family object (which makes one from that family at random), and makes only that object flash. I'm pretty sure I know why it's doing this, but is there any way to have it both make just the one object flash and make it a specific type without looping through all of the objects already created?

    Example Cap

  • I thought you wanted it to only make this new one flash

    but since that's happening, you must have meant something else

    i didn't even realize you could make it create a random one by asking it to create an object from a family


    if you want it to create the new random one and still make them all flash, then when you call your function tell it to "forget" picked objects instead of remember

    then they all flash when the random one is created

  • I'm quite surprised that "Create Object Sprite" didn't modify SOL for "Friend" family .

    In that case you'll have to pass two parameters with function: mouseX and mouseY and affect only object(s) which has those X Y coordinates:

    <img src="http://www.republika.pl/tymczasownik/events.png">

    You can also do it with "initialization" private value (I'd recommend that one since it's more universal). In that case you give all object of this family a private value "init" with default value 0. And in function "NewThing" you select only those, whose "init" = 0. When their actions (in this case flashing) is started, then you set their "init" to 1. Also on start of level you set all objects' "init" to 1 to avoid them flashing when first object is created.

    <img src="http://www.republika.pl/tymczasownik/events2.png">

  • Well, this wasn't the real thing I'm doing, it's just an example I threw together.

    lucid: You have it backwards.

    BROO: The first is too specific, and while the second would work, I was wondering if there was a way to do it without looping through every object each time. I guess there isn't right now, though.

    Thanks for the help, I guess I'll do the init thing (unless they add a Created event or something in the future).

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