Pegagittt
(Pegagit)
October 10, 2022, 11:53am
1
I tried something:
local Table = {}
print(Table[1])
table.insert(Table, "1")
print(Table[1])
table.remove(Table, table.find(Table, "2"))
print(Table[1])
This will print:
nil
1
nil
If thee 2 is not in the Table, it will remove something random in the Table, but why?
desinied
(desinied)
October 10, 2022, 11:57am
2
There is no 2 inside the table nor are you inserting it anywhere in your script. If table.find can’t find the entry it can’t return an index which would remove nothing.
Pegagittt
(Pegagit)
October 10, 2022, 11:58am
3
So if there is no 2 it removes just something inside?
desinied
(desinied)
October 10, 2022, 11:59am
4
Since you started the table at the top of the script as empty, once you removed the only entry in it which was “1” the table was empty. It didn’t remove anything because there was nothing to remove.
Pegagittt
(Pegagit)
October 10, 2022, 12:01pm
5
But im first inserting the 1 to the Table, then im removing the 2, what is not removing the 2 but the 1
desinied
(desinied)
October 10, 2022, 12:15pm
6
From what testing is showing, when table.find returns nil, table.remove() uses table[#table] which deletes the last entry in the table.
local Table = {"3","4","5"}
print(Table)
table.insert(Table, "1")
print(Table)
table.remove(Table, nil) -- Replcaed for testing, table.find(Table, "2") returns nil
print(Table)
Output:
1 Like
Pegagittt
(Pegagit)
October 10, 2022, 12:17pm
7
Thanks i also thought that, but was not sure