Author Topic: Most Efficient Method For Three Values [Solved]  (Read 2255 times)

Ok so I have five objects and I need a way to check if at least three %obj.values are the same, they will all be a number of 1-6. Anyone know of an efficient way to do this?
« Last Edit: May 09, 2013, 11:29:01 AM by jes00 »

Use a loop and check if they have the same values?

Use a loop and check if they have the same values?
Please explain further.

Well, what exactly are you doing?
Are you checking which of the 5 objects have all 3 variables to something specific?
Are you checking whether all 3 variables are equal on each individual object?
Are you checking whether all 5 objects have the same value for each of the 3 variables?

Well, what exactly are you doing?
Are you checking which of the 5 objects have all 3 variables to something specific?
Are you checking whether all 3 variables are equal on each individual object?
Are you checking whether all 5 objects have the same value for each of the 3 variables?
Each of the 5 objects has %obj.value, which is always a number between 1-6. I need to check if three of those four numbers are the same and if there are three that are the same, then I need to retrieve that number.

You could do something like that:
Code: [Select]
for(%i = 0; %i < %count, %i++)
{
    %val = %obj[%i].value;
    if(%finds[%val]++ >= 3)
    {
        %find = %val;
        break;
    }
}
%find = -1;
I think it should work

You could do something like that:
Code: [Select]
for(%i = 0; %i < %count, %i++)
{
    %val = %obj[%i].value;
    if(%finds[%val]++ >= 3)
    {
        %find = %val;
        break;
    }
}
%find = -1;
I think it should work
Oh. I'm so dumb.

Note that it won't work as intended if the minimum ammount of same values is below half the count of the objects

Note that it won't work as intended if the minimum ammount of same values is below half the count of the objects
): That's going to be the case 90% of the time then.

EDIT: Tested it, works perfectly.

Code: [Select]
case "3 Of A Kind":
for(%i = 1; %i < 6; %i++)
{
%this = "Yahtzee_Dice" @ %i;
%val = %this.value;

if(%finds[%val]++ >= 3)
{
%num = Yahtzee_Dice1.value + Yahtzee_Dice2.value + Yahtzee_Dice3.value + Yahtzee_Dice4.value + Yahtzee_Dice5.value;

break;
}
}
« Last Edit: May 09, 2013, 11:30:05 AM by jes00 »

Maybe you could be a bit more specific about what you're actually doing?

Looks like he's making that game where you throw 5 dices and win something if at least 3 are the same number

Looks like he's making that game where you throw 5 dices and win something if at least 3 are the same number


I have about 75% 90% of the script done and the GUI needs to be prettied up a little.