dude7271
(Logan)
February 23, 2021, 10:24pm
1
what I’m trying to do is have two identical tables (so I can keep the original table, and remove values from the other one)
ERROR: “invalid argument #2 to ‘remove’ (number expected, got string)”
here is the two tables I used:
local Surfaces = {
"Top",
"Bottom",
"Left",
"Right",
"Front",
"Back"
}
local Rem_Surface = {
"Top",
"Bottom",
"Left",
"Right",
"Front",
"Back"
}
and here is where I remove one of the values:
local surface = Mouse.TargetSurface
for i, v in pairs(Surfaces) do
if surface.Name == v then
table.remove(Rem_Surface,v)
end
end
I can’t seem to find the issue, any help is appreciated!
sjr04
(uep)
February 23, 2021, 10:25pm
2
table.remove takes an index to remove, not the value.
- table.remove(Rem_Surface,v)
+ table.remove(Rem_Surface, i)
1 Like
sleitnick
(sleitnick)
February 23, 2021, 10:28pm
3
Along with what @sjr04 said, it is also good practice to break the loop after the removal too, otherwise you waste CPU cycles scanning over nothing necessary:
local surface = Mouse.TargetSurface
for i, v in pairs(Surfaces) do
if surface.Name == v then
table.remove(Rem_Surface, i)
break
end
end
1 Like
dude7271
(Logan)
February 23, 2021, 10:32pm
4
That makes sense, thank you for that!
1 Like