4/2/2024 0 Comments Lua table insert keyYou can use any value except nil and nan. However, table keys don't have to be integers. assuming standalone Lua, using print - replace with outputChatBox or another output function if running in MTA Using index operator, you can retrieve the associated value from the key: Because table.insert treats the table as an array and because it inserts at the end of the sequence if position argument is omitted, we end up with values "apple", "banana", "lemon" and "orange" values under keys 1, 2, 3 and 4 respectively. It creates an empty table, then uses table.insert to insert values. Various functions that operate on tables, including those in table namespace, treat them as arrays. Take this example: But it seems necessary because I see people using Lua tables but not taking advantage of their flexibility.Īnyway, Lua tables are often used as arrays - that is, data structures that store values under consecutive integer keys starting at 1 (0 in most other languages, but that's another story), making a sequence. I don't know why I even have to point this out since this is something I figured out automatically in my early days of MTA scripting.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |