Iterating over all instances and then creating new instance causes strange behaviour

0 favourites
  • 7 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I would like to iterate over all instances of an object family, and for each instance, I would like to create a new instance.

    The issue is that it sometimes creates multiple instances of the same object, and I don't understand why.

    In my playground, I have two instances, A and B, and expect another A and B to be created.

    But instead, sometimes it creates AA, BB, AB. I would understand that when iterating over the instances, it includes the newly created once, but then I would expect an infinite loop which also doesn't happen. Instead, it only always creates two new instances.

    To avoid an infinite loop, I added another condition to ensure it only iterates over the instances off-screen. But it is still the same issue.

    Does anyone have an idea what's going wrong here?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you mean that it doesn't always create the matching object like over A it creates B instead of A then this is intentional, if you use Family it creates a random object inside Family.

  • You can't leave the expression empty in for each (ordered) dialogue. At least a property of the object required. By default construct create random family instances plainly. From what "ordered" suggest a filter criteria needed for example 'family.Y' will filter family instances based on their Y position in ascending/descending order.

    So for your case the expression require ObjectTypeName:

    dropbox.com/s/sd1f6ikhqfupmj5/family_order_byType.c3p

  • You can't leave the expression empty in for each (ordered) dialogue. At least a property of the object required. By default construct create random family instances plainly. From what "ordered" suggest a filter criteria needed for example 'family.Y' will filter family instances based on their Y position in ascending/descending order.

    So for your case the expression require ObjectTypeName:

    https://www.dropbox.com/s/sd1f6ikhqfupmj5/family_order_byType.c3p?dl=0

    okay I see..this does not seem so intuitive to me but alright. How do I access the last created object when it's created by name?

  • If you mean that it doesn't always create the matching object like over A it creates B instead of A then this is intentional, if you use Family it creates a random object inside Family.

    Interesting. I think the behavior should be different when I specifically iterate over all family instances right before. I kind of expect the family object in the create method to be the same .

  • Alternative way (more intuitive with extra events):

  • > If you mean that it doesn't always create the matching object like over A it creates B instead of A then this is intentional, if you use Family it creates a random object inside Family.

    Interesting. I think the behavior should be different when I specifically iterate over all family instances right before. I kind of expect the family object in the create method to be the same .

    Yes it's an easy assumption to make of course. If you want to create the same object you probably have to go down to the object level in the pick and create events, so for this Families will not be useful.

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