|
| 03 Sep 2017 12:03 PM |
| Is there a method to find how many values are in a table, like table.highest or table.amount something like that. I'd rather not use a for loop to count the values if I don't need to. |
|
|
| Report Abuse |
|
|
Zoumagura
|
  |
| Joined: 15 Feb 2008 |
| Total Posts: 117 |
|
|
| 03 Sep 2017 12:04 PM |
| What's wrong with a for loop? As far as I know it's probably the easiest way. |
|
|
| Report Abuse |
|
|
Duusskk
|
  |
| Joined: 27 Aug 2013 |
| Total Posts: 651 |
|
|
| 03 Sep 2017 12:05 PM |
| Yup, you need to use a for loop if you have non-numerical keys. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2017 12:05 PM |
| A method that I can call on a single line is more efficient than using a for loop. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2017 12:05 PM |
| Use the unary operator, #### to get the number of values in the array. local ex={1,2,3,4,"lol"} ########## --> 5 |
|
|
| Report Abuse |
|
|
| |
|
Zoumagura
|
  |
| Joined: 15 Feb 2008 |
| Total Posts: 117 |
|
|
| 03 Sep 2017 12:09 PM |
| If your table is all numbers, save the last value you put into the table and you'll have the highest value in the table. |
|
|
| Report Abuse |
|
|
Duusskk
|
  |
| Joined: 27 Aug 2013 |
| Total Posts: 651 |
|
|
| 03 Sep 2017 12:10 PM |
| Finding number of elements in a table, unary: local items = {"a", "b", "c"} print (#items) -- 3 However that won't work if you have a table like this local data = { cash = ### ###### = 0 } print(#data) -- 0 This is when you need a for loop. |
|
|
| Report Abuse |
|
|