FLASH CS4 - Need to compare three values
Good morning to the collective! I have THRE variables containing randomly generated numbers. I need to determine programmatically which TWO are the largest numbers. What is the simplest way to do that in ActionScript 2.0? I'm trying If Else statements but can't seem to get the pattern correct. Thanks in advance!
Thank you! May I ask for a little more help?
Thank you thank you! I used the array structure to produce the 3 values in the correct order. Actually, I changed the order to ASCENDING and made i equal to 1 so it only reports the 2 numbers I need. However, I'm afraid my meager skills require a bit more assistance.
To briefly explain, I am developing a "Family Feud" game to be played live and operated by an operator (me), moderated by a live host (client). I am faced with 6 Teams playing 2 at a time, resulting in 3 winners. I then need to programmatically determine the two highest scores (which you have already done for me) and using the variables already established, populate a final round without knowing in advance who the two teams will be.
I now need to take these 2 highest numbers (game scores) which already equate to their individual numeric variables (round1HighScore, round2HighScore and round3HighScore), and produce their associated team name variables (round1Winner, round2Winner and round3Winner). I am again trying to use a series of "if" and "else if" statements nested in the for/next loop to determine each score's equivalent variable and then declare the associated name variable as one of the 2 finalists.
Confused yet?
I'd be happy to copy and paste what I have but I'm afraid my skills stopped developing years ago as the live gaming is all I really use Flash for and once I have built the games they just need re-skinned/customized per job. I'm still stuck in ActionScript 2 and do everything in the longest most convoluted way possible using the most basic commands. I'm sure there are much simpler ways to do what I've already done, but so far it all works. This 3 into 2 challenge has me stymied though.
Thanks again for any help you can offer,
Brian
Quote:
Originally Posted by
fruitbeard
Hi,
Put them in an array and sort the array numerically.
PHP Code:
var number1:Number = Math.round(Math.random() * 10000);
var number2:Number = Math.round(Math.random() * 10000);
var number3:Number = Math.round(Math.random() * 10000);
// *** use above vars or below math
var numberArray:Array = new Array();
numberArray.push({name : "Number 1", value : Math.round(Math.random() * 10000) });// or your number vars instead of the math
numberArray.push({name : "Number 2", value : Math.round(Math.random() * 10000) });
numberArray.push({name : "Number 3", value : Math.round(Math.random() * 10000) });
numberArray.sortOn("value",Array.DESCENDING | Array.NUMERIC);
for (var i:Number = 0; i < numberArray.length; i++)
{
trace(numberArray[i].name + ", " + numberArray[i].value);
}
I'm sure there might be other perhaps easier ways of doing it but you have a nice object array to work with there