0 Favourites

# How do I match objects.....

• 5 posts
• 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.

• 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.

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

Construct 3 users don't see these ads
• 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.

• 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.

• an array, i kinda dont know how to use them yet. time for some tutorials. anyway thanks again mekonbekon .

• 5 posts