![]() ![]() Only way to fix it was to initialize elements 1 through 5 with an empty string first, and then inserting the actual values in random order. bad argument 1 to 'remove' (position out of bounds) Here is the code. Next try was to avoid table.insert and instead use test = "5" etc. Inserting at position 1 appends, and the next insert reorders the other elements?!? ![]() Translating to english it means that the correct usage of table.insert is: table.insert (table, value). Another thing: you could think at table.insert like: just put that there at the end. Test output after each insert delivered this interesting behavior: Īctually it worked better than expected (I thought that inserting to a table with two elements at position 4 would probably append), but the lines 2 and 3 got me absolutely confused. So seing your code (i dont know if its an example or not) but your tests T is lowercase, remeber that lua is case sensitive. I'm new to lua and hadn't worked with table.insert before (only read that tables support both an associative and an array form), but I was pretty sure it couldn't work this way, so I made a little test: local test = I needed to add elements to a lua table in a certain order and tried to insert each element to its final position (but in a random order). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |