# How do I match objects.....

Get help using Construct 2

### » Sat May 06, 2017 11:18 pm

I have looked around, haven't found anything that really helps but if you have seen my issue before in a different post please feel free to link it.

well what im trying to do is simply match player choice to AI's choice.

Like for example ai selected a meal with 3 different sides in it. i want said player to select meal with corresponding sides.

ai sees the right order deletes his order and gives points.

Any help is appreciated thanks in advance.
B
7
S
3
G
1
Posts: 6
Reputation: 1,143

### » Sun May 07, 2017 8:57 am

Hi @red1m3n,

As long as the three sides are all different and it doesn't matter which order you select the sides in you can use a neat little addition trick:

Give each side an instance variable "value".
For each side assign "value" an increasing power of two e.g.

sideA = 1
sideB = 2
sideC = 4
sideD = 8
sideE = 16
etc

Create a global called "AITotal".
Assign AITotal the sum of "value" for the three selected AI sides. This value will always be unique for each different combination of sides.
Create a global called "PlayerTotal".
Assign PlayerTotal the sum of "value" for the three player selected sides.
If AITotal is equal to PlayerTotal then the player has selected the same sides.

In fact I think this might work even if you have duplicates of the sides in the choice of three.
B
24
S
9
G
4
Posts: 515
Reputation: 4,472

### » Sun May 07, 2017 10:01 am

wow man thanks!! I wasnt thinking about making it a math problem. I might even be able to make it into a function with alittle tweaking.

i wonder if that will still maybe work if AI orders multiple meals hmm...

maybe just adding a second variable called value2 and might not have to clone the sides again.
B
7
S
3
G
1
Posts: 6
Reputation: 1,143

### » Sun May 07, 2017 10:15 am

@red1m3n

Or have a second variable orderNo and a global for each order. If you have a lot of orders then you might just want to switch to using an array instead of using globals:
Each row would be an order and the columns would be Main,Side_1,Side_2,Side_3. You could still use the addition trick I described above to compare AI order and player selection.
B
24
S
9
G
4
Posts: 515
Reputation: 4,472

### » Sun May 07, 2017 10:22 am

an array, i kinda dont know how to use them yet. time for some tutorials. anyway thanks again @mekonbekon .
B
7
S
3
G
1
Posts: 6
Reputation: 1,143

Return to How do I....?

### Who is online

Users browsing this forum: dop2000, SERGIOManOwaR and 2 guests