Code: Select all
table.remove(dropDown.items, dropDown.selected_index)
Do I have to clear and recreate in order to remove an item? I'd really like not to.
Code: Select all
table.remove(dropDown.items, dropDown.selected_index)
Code: Select all
drop_down.items[drop_down.selected_index] = nil
dorp_down.set_item(drop_down.selected_index, nil)
That doesn't do what he asked to do.kikker450 wrote:check the lua commands next time before asking these kinds of questions.
you have at least two options:Code: Select all
drop_down.items[drop_down.selected_index] = nil dorp_down.set_item(drop_down.selected_index, nil)
Code: Select all
table.remove(recipe,"result")
Code: Select all
function copy_table(table, omit_callback)
local result = {}
for i, v in pair(table) do
if not omit_callback(i, v) then
result[i] = v
end
end
return result
end
Code: Select all
local props_to_omit = {
foo = true,
bar = true,
result = true
}
-- copy will contain every property from some_table except foo, bar and result
local copy = copy_table(some_table, function (key) return props_to_omit[key] end)
That's the official (correct) way to remove a key from a table in Luabobingabout wrote:Sure, in this specific case I can just set result = nil, but that doesn't feel right.
Code: Select all
variable["result"] = nil -- removes the key "result" from the table "variable".
That's good to know I was missing the "delete" keyword in Lua that JS has. Now I also understand why I couldn't create gaps in an array by using nil, e.g. {nil, nil, nil} will produce an empty table {}, while in JS it is possible to have an array full of undefineds/nils.Rseding91 wrote:That's the official (correct) way to remove a key from a table in Luabobingabout wrote:Sure, in this specific case I can just set result = nil, but that doesn't feel right.
Code: Select all
variable["result"] = nil -- removes the key "result" from the table "variable".
Correct. Also ipairs is virtually never needed - just use pairs and it works the same except you don't get these annoying problems. Also also: Factorio is written in C++ - not CNexela wrote:variable["result"] result is a named key setting it to nil is the correct way as ipairs doesn't work on it anyway. If you need to keep an ordered array ordered then use table.remove(table, index)
for stuff in data.raw my guess is (and I could be wrong) that factorio c code will handle converting the skipped stuff in an ordered arrary correctly for use in the game.
Code: Select all
local items = dropDown.items
table.remove(items, 1)
dropDown.items = items
Because I don't use either of those. I use Skype and Telegram. I don't use Discord for a good reason, last time I tried it, it was a bug riddled piece of shit that locked up my computer for a good 20 minutes before it would let me do anything. Then I tried to "search" for a friend to be greeted with a "you need to add their 4 digit number to this name so that we know which one you are looking for". If I knew the number, I wouldn't be searching for it!Rseding91 wrote:Also also also, why aren't you on IRC or Discord?