Referencing specific instance of multiple duplicate objects

This forum is currently in read-only mode.
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • I'm having trouble writing Events/Actions that deal with a particular instance of an object, when I have multiple instances of an object in the layout. Specifically, there's 64 instances of sprite A (in an 8x8 grid) and one instance of sprite B. When sprite B overlaps an instance of sprite A (#1), I want to set a private variable in sprite B based on the animation frame of the overlapped sprite A, then move sprite B over a different sprite A (#2), and compare the sprite B private variable to the animation frame of sprite A #2.

    The first part works fine (set the sprite B private variable), but the second part (the comparison with sprite A #2) doesn't seem to be working; from what I can tell, it's doing the comparison between sprite B and sprite A #1, instead of between sprite B and the sprite A #2.

    I really hope this makes some kind of sense, and that someone can help. If there's something helpful and applicable that I missed in one of the tutorials, kindly point the way. I'll try and figure out how to post the .cap, which I'm guessing would also be useful. Edit: Here's a link. The relevant code is under the 'Move Attempt' group.

    Alternately, if anyone has any better suggestions on how to go about putting together a Match-3 type game in Construct, I'm all ears. As awesome as Construct is, it's still forcing me to exercise the computer science/math/logic parts of my brain that I haven't used properly in years.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • when using a 'Object A is overlapping/colliding with Object B' condition, Construct automatically puts the two objects in question into the SOL (selected objects list), meaning that any following Actions will always deal with the colliding/overlapping instances of A and B. since the loop that moves your collision-checker is a subevent of an event using that kind of condition, it can always only refer to the same instance.

    a solution to this could be to restructure your code, so that the collision detection takes place in a subevent and does not influence picking adversely. or you could use families as a workaround: since it is possible for an object to belong to two different families, you can use that to pick object's outside of the current SOL (e.g. check collision for Family A (which reduces the SOL of Family A to a single instance), then afterwards loop through Family B (whose SOL still contains all instances), with Object A belonging to both).

  • when using a 'Object A is overlapping/colliding with Object B' condition, Construct automatically puts the two objects in question into the SOL (selected objects list), meaning that any following Actions will always deal with the colliding/overlapping instances of A and B.

    That confirms my suspicion. I'll try restructuring my code with this in mind. Thanks for the info and the suggestions.

  • Also, you could use a global variable to store the instance's pvariable value and use a function call wtih "forget" picked then repick in the function with global being equal to the pvariable.... But I'm bad at Construct and make mistakes all the tinme, so don't listen to me.

  • but you're right, the fact that Functions can be made to "forget" the current SOL is another workaround for this kind of problem. (i forgot about that one, too...)

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