Finding the smallest number from a table?
AlkaPP
Member, PRO Posts: 194
Hi all,
I have a table with 10 rows. Each row has a random number. How can I find the smallest number among those 10 rows?
Thanks.
My Gamesalad Games On App Store:
Greedy Chubby: https://itunes.apple.com/us/app/greedy-chubby/id834371213?ls=1
Comments
There is no function to do this. I have attached a simple method which will work for values up to a hundred in a couple of seconds. Once you get over that it might take too long for you to use. Search for "Fast For Loops" and use that method to increase its search speed.
Another member came up with a method called "bubble sort" I haven't looked into it but it could work better, do a search for it.
Other than that a complex set of rules to take the values one by one and insert them in a new table in order would be the only other way I could think of.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
That's not completly true,it's a function called min()
I use this function alot in my pirate poker game,and it works perfect.
Just create a attribute called MinValue
Then when you want to collect the smallest value do:
Change attribute MinValue to
min(tableCellValue(yourtable,1,1),tableCellValue(yourtable,2,1),tableCellValue(yourtable,3,1),tableCellValue(yourtable,4,1),tableCellValue(yourtable,5,1),tableCellValue(yourtable,6,1),tableCellValue(yourtable,7,1),tableCellValue(yourtable,8,1),tableCellValue(yourtable,9,1),tableCellValue(yourtable,10,1))
Kind of long expression but not hard to understand. It basiclly check the min value of the tableCellValues of row 1-10 in column 1
Hope it helps
@Fajlajp you are correct I left out the word "specific". I like your solution I hadn't thought of it. I was thinking dynamically so this or another user could adjust the table size before or during runtime without having to adjust the code hence the meMaxRows attribute.
I did this because in the NB's and coming soon to the regular releases are the new add and remover table row functions. I was thinking other users looking at this will have very different size tables.
I have attached a new version with your method in it. It is much faster. @AlkaPP when clicking on the first method wait for a second or two for the loop to complete.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template