Picking instances through variables and distance

0 favourites
  • 11 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi everyone, I want to create a royal rumble type game, where the results are already predetermined. This is what I had plan to use to create it, but please feel free to share if you can think of a more effective approach.

    Each object will have 2 lives, so they need to be hit twice before they lose and removed from the game. Each instance will have their final ranking set in their own variables, ranking from 1 to 6. They will each approach the nearest instance, and fight it out for a while. The one with the lowest ranking, will lose and be knocked back. Both of them will than go after the nearest instance, but not themselves again, and fight and continue on until only the winner is left.

    The problem I am having is comparing between instances and selecting one based on the variable being higher or lower. I just can't seem to find a way to select an instance based on two conditions. For example, pick nearest to sprite.UID=variable, but than I can't say exclude this sprite instance because they just fought, or say which one should lose when compare between the two variables.

    Would really appreciate any help on this. Thanks.

  • I set this up in a kind of longwinded way, it can probably be cut down shorter. When two objects 'fight' or I assume collide or overlap, you can pick the nth instance of the overlap using system compare. In the overlap, one sprite will be instance 0, the other will be instance 1. You can compare that the instance variable rank for instance 0 is less than the variable rank for instance 1 and if so set instance 0 to destroy or 'lose', then put else set instance 1 to lose. This might be useful when doing these kind of 1 on 1 battles, it's Pick nth instance in system compare.

  • Thank you ! What you explain makes perfect sense, but I seem to have problem with building up the correct events for it. I tried:

    On Sprite is overlapping Sprite


    Pick nth instance: Sprite instance 0

    Sub Sub:

    System compare: Sprite(0).variable > Sprite(1).variable: Event Action

    Else: Event Action

    I thought it would work like this, haha but obviously it didn't. Which part am I getting wrong?

  • The easiest way to deal with this kind of issue is to put Sprite into a Family. Now you have two distinct object types, and your events can deal with Sprite on one side, and Family on the other.

  • But the problem is if I use family, I can't compare the instance variables anymore. The family only works will variables and behaviors that assigned to it and not those within it if I am not wrong.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you add the variables and behaviors to the Family, they are available on the base object also! So you can compare Sprite.Foo = Family.Foo, for example.

  • blackhornet thanks I never knew that if I set the family variable, it is also automatically assigned to each object as well. But I am still having problems comparing between instances. Could you please show me how to get it to work properly?


    I have a capx here that I can't get to work. I want each sprite to move to the nearest sprite, than when overlapping, the one with the higher position is destroyed. Would appreciate any help you can share. Thanks.

  • http://www.blackhornettechnologies.com/Construct2Stuff/InstanceExample_BHT.capx

    It does get a bit complicated as you can get the same object in both lists, so you have to eliminate that, and Destroy doesn't actually destroy immediately, so you have to account for that also.

  • Here was my event, for reference. I set the sprites to drag and drop. Make them collide to see how the weaker ranked one is destroyed. I store one of the rank variables temporarily in a global variable to compare. https://dl.dropboxusercontent.com/u/495 ... mpare.capx

  • Thank you blackhornet and I'm travelling right now so away from my computer, will go back and study both your capx after 3 days. Again, thank you so much guys, really appreciate it!

  • Thanks guys, finally returned home to check both capx out. Wow, honestly didn't expect it to be that simple. Haha thank you so much for that....and here I was trying so much complex condition and selections.

    blackhornet, thank you for that capx. That is exactly what I was trying to implement in my game. It looks perfect for my case.

    Thanks to both of you guys, I learned something new. Really appreciate it, both of you.

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