How do I match objects.....

Get help using Construct 2

Post » 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
2
G
1
Posts: 6
Reputation: 993

Post » 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
19
S
8
G
3
Posts: 423
Reputation: 3,964

Post » 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
2
G
1
Posts: 6
Reputation: 993

Post » 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
19
S
8
G
3
Posts: 423
Reputation: 3,964

Post » 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
2
G
1
Posts: 6
Reputation: 993


Return to How do I....?

Who is online

Users browsing this forum: guannstar and 18 guests