A list of values in an assignment statement where many variables are assigned at once is also a tuple. A function call to a function that returns many values evaluates to a tuple. Return to the main Lua page to learn about other Lua code libraries. In Lua, a distinction is made between a tuple, a simple list of values, and a table, a data structure that maps indices to values. table.sort ( numbers, descending ) sorts the table using a custom descending comparison function.Ĭongratulations! You've now created, tested, and understood a Lua script that uses the Table library.Since the table was sorted prior to removal, this will remove the lowest value from the table. table.remove ( numbers, 1 ) removes the element in position 1 from the table.table.sort ( numbers ) sorts the numbers table in the default ascending order.ncat ( numbers, ', ' ) retrieves the values in the table numbers and converts them into a string concatenated with ', ' separators between each value.table.insert ( numbers, math.random ( 1, 10 )) calls the math library random function to retrieve a random number between 1 and 10, inclusive, and then inserts that value into the numbers table.for i = 1, 10, 1 do creates a loop code block that will repeat 10 times.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |