Picking instances through variables and distance

Get help using Construct 2

Post » Fri Oct 28, 2016 2:35 pm

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.
B
42
S
20
G
31
Posts: 685
Reputation: 20,221

Post » Sat Oct 29, 2016 11:57 am

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.
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Sat Oct 29, 2016 2:28 pm

Thank you @plinkie! 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
Sub:
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?
B
42
S
20
G
31
Posts: 685
Reputation: 20,221

Post » Sat Oct 29, 2016 2:45 pm

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.
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Sun Oct 30, 2016 3:30 am

@blackhornet. 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.
B
42
S
20
G
31
Posts: 685
Reputation: 20,221

Post » Sun Oct 30, 2016 3:55 am

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.
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Sun Oct 30, 2016 7:52 am

@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?

http://www.mediafire.com/file/mktlt9oaa5amai0/InstanceExample.capx

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.
B
42
S
20
G
31
Posts: 685
Reputation: 20,221

Post » Sun Oct 30, 2016 2:20 pm

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.
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Sun Oct 30, 2016 6:02 pm

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
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Mon Oct 31, 2016 2:51 am

Thank you @blackhornet and @plinkie. 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!
B
42
S
20
G
31
Posts: 685
Reputation: 20,221

Next

Return to How do I....?

Who is online

Users browsing this forum: tarek2, wenwen11212016 and 8 guests