Page 1 of 1

Can I removeitem table?

Posted: Sun Jun 25, 2017 11:36 pm
by Bugala
I am trying following:

Code: Select all

table = { ["item1"]="test1", ["item2"] = "test2"}

item = RemoveItem(table)
ForEach(table, DebugPrint)
What I was hoping to achieve was for either "item1" or "item2" with its "test1" / "test2" to disappear from table, however, they stay intact, which means it didnt work.

Is there any way I can actually make this happen?

Re: Can I removeitem table?

Posted: Mon Jun 26, 2017 7:24 pm
by SamuraiCrow
The purpose of RemoveItem is to renumber the numerical keys in a Hollywood "array". Assigning the value corresponding to the first key to Nil in a one shot use of an iterator is what you are trying to do, it seems.

Use NextItem to get the first key, use item=table[key] to get the value, then use table[key]=Nil to remove it from the table.

Re: Can I removeitem table?

Posted: Mon Jun 26, 2017 9:08 pm
by Bugala
Thanks, that is at least better than the alternatives i was thinking.

Re: Can I removeitem table?

Posted: Mon Jun 26, 2017 9:21 pm
by SamuraiCrow
After some thoughts, perhaps the first two steps of my suggested solution can be combined by using the second returned value on NextItem.