maqleod Posted June 11, 2007 Share Posted June 11, 2007 I am looking for an efficient way to compare 6 numbers and find out what the lowest and the highest are. I'm writing a dice roller and I want it to be able to apply functions to the lowest or highest roll, but I need to separate those rolls so I can do that. I looked through the math include and all I found was a way to compare two numbers, and modifying that for 6 would create a very convoluted mess, is there a better way? [u]You can download my projects at:[/u] Pulsar Software Link to comment Share on other sites More sharing options...
smashly Posted June 11, 2007 Share Posted June 11, 2007 Hi, I don't have an example , but maybe you write the 6 numbers to an array and use _ArraySort() sort function in AutoIt help file under User Defined Functions ->Array Management ->_ArraySort. Once you've sorted the array you can use first or last element in the array as the highest or lowest value (depending on the way you sort the array, Descending or Ascending). Good Luck Cheers Link to comment Share on other sites More sharing options...
BrettF Posted June 11, 2007 Share Posted June 11, 2007 (edited) Try These: They return the biggest, and the smallest of the 6 numbers. Returns The Biggest: Func _GetBigNumber ($1, $2, $3, $4, $5, $6) Local $max = $1 For $i = 1 to 6 If $max < Eval($i) Then $max = Eval($i) EndIf Next Return $max EndFuncoÝ÷ Ùº¹ìN©ezËZºÚ"µÍ[ÈÑÙ]ÛX[[X ÌÍÌK ÌÍÌ ÌÍÌË ÌÍÍ ÌÍÍK ÌÍÍBBSØØ[ ÌÍÛZ[H ÌÍÌBBQÜ ÌÍÚHHHÈ BBRY ÌÍÛZ[ ÝÈ][ ÌÍÚJH[BBBIÌÍÛZ[H][ ÌÍÚJBBBQ[YBS^BT] ÌÍÛZ[[[oÝ÷ Ùº¹ìav§jºÚËMújºÚË Hope it helps EDIT: Spelling... Edited June 11, 2007 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Valuater Posted June 11, 2007 Share Posted June 11, 2007 _ArraySort() 8) Link to comment Share on other sites More sharing options...
Siao Posted June 11, 2007 Share Posted June 11, 2007 _ArraySort()8)It's kinda slow tho. Almost the same as doing_Min(_Min(_Min(_Min(_Min($n1,$n2),$n3),$n4),$n5),$n6)_Max(_Max(_Max(_Max(_Max($n1,$n2),$n3),$n4),$n5),$n6)Bert's last function to return min/max runs twice faster... Just sayin... "be smart, drink your wine" Link to comment Share on other sites More sharing options...
maqleod Posted June 12, 2007 Author Share Posted June 12, 2007 (edited) I forgot to take something into account, I allow the user to select which dice are to be rolled. Meaning of the six dice, they can choose to roll die 1 and die 3. So what I really need now is a way to make the function that selects the lowest or highest number be able to tell which dice were selected and choose the lowest or highest of those. if I use the function as Bert suggested, I'll get an error parsing function call because some of the variables won't exist if the user doesn't use all 6 dice. Would the _ArraySort() function make that work better for what I need or is there a way to modify Bert's to make it more efficient? Edited June 12, 2007 by maqleod [u]You can download my projects at:[/u] Pulsar Software Link to comment Share on other sites More sharing options...
BrettF Posted June 12, 2007 Share Posted June 12, 2007 I forgot to take something into account, I allow the user to select which dice are to be rolled. Meaning of the six dice, they can choose to roll die 1 and die 3. So what I really need now is a way to make the function that selects the lowest or highest number be able to tell which dice were selected and choose the lowest or highest of those.if I use the function as Bert suggested, I'll get an error parsing function call because some of the variables won't exist if the user doesn't use all 6 dice.Would the _ArraySort() function make that work better for what I need or is there a way to modify Bert's to make it more efficient?I guess if you just fill the other numbers with 0s??? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
maqleod Posted June 12, 2007 Author Share Posted June 12, 2007 I guess if you just fill the other numbers with 0s???but won't it then choose those as the lowest number? [u]You can download my projects at:[/u] Pulsar Software Link to comment Share on other sites More sharing options...
/dev/null Posted June 12, 2007 Share Posted June 12, 2007 but won't it then choose those as the lowest number?I think he implied that you are able to modify the functions to take care about the special value 0 !??! __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now