rasterscan Posted April 23, 2022 Share Posted April 23, 2022 (edited) Hi folks. I have a set of results, integers 24 , 36, 48 and 52. What math would I use to select, or winkle out, the highest number in a set of results ? So the highest number can be declared the winner. Does that even make sense. Edited April 23, 2022 by rasterscan Link to comment Share on other sites More sharing options...
Rolig Loon Posted April 23, 2022 Share Posted April 23, 2022 list MyNums = [24,36,48,52]; default { state_entry() { integer iMax; integer i; while ( i < llGetListLength(MyNums) ) { if ( llList2Integer(MyNums,i) >= iMax) { iMax = llList2Integer(MyNums,i); } ++i; } llSay(0,"The largest number is " + (string)iMax+ "."); } } Not optimized, but simple. 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted April 23, 2022 Share Posted April 23, 2022 Or llSay(0, "The largest number is " + (integer) llListStatistics(LIST_STAT_MAX, MyNums) + "."); 😉 4 Link to comment Share on other sites More sharing options...
Fritigern Gothly Posted April 23, 2022 Share Posted April 23, 2022 Or you could store every number in a list and use llListSort() ( https://wiki.secondlife.com/wiki/LlListSort ) so you can use the other numbers for additional processing (top-3 number, bottom 3, lowest, etc.) 1 Link to comment Share on other sites More sharing options...
Mollymews Posted April 24, 2022 Share Posted April 24, 2022 sometimes we want to get the index of the highest number when there is a avatar associated with the high score in this case then integer high_score; integer index_of_winner; integer i; for (i = 0; i < llGetListLength(scores); i++) { integer this = llList2Integer(scores, i); if (this >= high_score) { high_score = this; index_of_winner = i; } } llOwnerSay( "The winner is avatar no. " + (string)index_of_winner + " with a score of " + (string)high_score ); 1 Link to comment Share on other sites More sharing options...
Sloverdrive Posted April 24, 2022 Share Posted April 24, 2022 You should use llListStatistics() for that. 1 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted April 24, 2022 Share Posted April 24, 2022 12 minutes ago, Sloverdrive said: You should use llListStatistics() for that. 22 hours ago, Rolig Loon said: llSay(0, "The largest number is " + (integer) llListStatistics(LIST_STAT_MAX, MyNums) + "."); 😉 🙂 1 Link to comment Share on other sites More sharing options...
Sloverdrive Posted April 24, 2022 Share Posted April 24, 2022 2 hours ago, Sloverdrive said: You should use llListStatistics() for that. On 4/24/2022 at 2:18 AM, Rolig Loon said: llSay(0, "The largest number is " + (integer) llListStatistics(LIST_STAT_MAX, MyNums) + "."); 😉 🙂 Sorry. I had missed your second post.😖 1 Link to comment Share on other sites More sharing options...
rasterscan Posted April 25, 2022 Author Share Posted April 25, 2022 Thankyou you folks are awesome ! 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now