I seem to be having an issue, I get how table.insert works, but somehow i cant do
if table.isMember(fociinarea, matches[2]) then
table.remove(fociinarea, matches[2])
end
the matches[2] is one of the different names in the fociinarea table...
I gathered you cant remove a word from the table and just the 'number' of the position it is in, so my question is.. how do you remove the number or find which number it is? im well confused..
Table Remove
Re: Table Remove
You have to loop through the table.
Re: Table Remove
Interestingly enough there is a TableUtils.lua included in mudlet-lua, and therein you can find
such functions (not yet documented it seems) like listRemove. This would simplify your code to this:
such functions (not yet documented it seems) like listRemove. This would simplify your code to this:
Good luck, G.
Re: Table Remove
There's no need to use them, they're left there for backwards compatibility - table.remove() is better to use.
Re: Table Remove
Not to be nitpicky, since you said that those functions are left there for backwards compatibility, but usually it is better to use already included code, especially when it does exactly the same thing as the aforementioned solution using table.remove.
On the other hand i do think that including some more usefull functions in TableUtils might be not a bad idea for the future, since it will simplify things for "lua newbies", but that is up to you guys.
Regards, G.
On the other hand i do think that including some more usefull functions in TableUtils might be not a bad idea for the future, since it will simplify things for "lua newbies", but that is up to you guys.
Regards, G.
Re: Table Remove
Yeah, the included code, that's documented everywhere and way more, is table.remove(). The list functions just duplicated table functions while offering no extra help and just giving the confusion of choice between the same equivalents.
They're left in there because we don't break peoples scripts, so whomever used them before still can.
They're left in there because we don't break peoples scripts, so whomever used them before still can.
Re: Table Remove
Table.remove does not accept the element, it accepts the key, which I'm sure you are aware of. So no, listRemove even though named poorly does not duplicate table.remove functionality.
Sure, probably it could have been named table.removeelem...
Sure, probably it could have been named table.removeelem...
Re: Table Remove
Ahh, my fault. There's the table.remove, table.index_of pattern instead... hm.
Re: Table Remove
I considered it, but it does remove only one occurence. Still, since mudlet already offers index_of it might offer table.removeelem while retaining backward compatibility by a simple assignment to listRemove