13 posts
Posted 20 April 2013 - 07:32 AM
Hey, I have something like this:
resources = {["planks"]={["side"]="back",["code"]=4,},["cobble"]={["side"]="back",["code"]=2,},["dirt"]={["side"]="back",["code"]=1,},}
(3 tables inside one table)
Everything is working just fine. My question is: How to delete one specific table. For example I want delete cobble from resources. I tried use table.remove() but it didn't work.
Thnx for answer.
1688 posts
Location
'MURICA
Posted 20 April 2013 - 07:45 AM
table.remove() only works with numbers. Just set the index to nil.
resources.cobble = nil
13 posts
Posted 20 April 2013 - 08:00 AM
thnx, just made small change
name = read()
resources[name] = nil
2088 posts
Location
South Africa
Posted 20 April 2013 - 08:26 AM
You could have a table like this.
resources = {
{block="planks",side="back",code=4},
{block="cobble",side="back",code=2},
{block="dirt",side="back",code=1},
}
But I guess then you would have to loop through the table checking the block string if it's the one you want.
Also won't have a table with a lot of nil indexes.
47 posts
Posted 20 April 2013 - 08:32 AM
What will the
side="back"
do?
Put the Item into the Crafting Table?
1688 posts
Location
'MURICA
Posted 20 April 2013 - 08:34 AM
@remiX
Setting a variable or table index to nil removes it; you would get nil from an undefined variable as you would from an unset variable. Setting something to nil is like not having set it at all.
"Having a bunch of nil indexes" is no problem, because there are already a lot of them in the table.
2088 posts
Location
South Africa
Posted 20 April 2013 - 08:41 AM
@remiX
Setting a variable or table index to nil removes it
Really? Oh. Cool xD
"Having a bunch of nil indexes" is no problem, because there are already a lot of them in the table.
Yeah true dat.
But will textutils.serialize not have the ones that have been set to nil?
13 posts
Posted 20 April 2013 - 08:43 AM
What will the
side="back"
do?
Put the Item into the Crafting Table?
No, it's a little complex. I have a row of 16 barrels, and every barrel has its own colored wire, together these wires are connected to one bundled cable. Thats why there is code for.
Side determines where is bundled cable connected to computer. So you can connect 6 bundled cables with 16 different wires (96 total).
1688 posts
Location
'MURICA
Posted 20 April 2013 - 08:45 AM
@remiX
Setting a variable or table index to nil removes it
Really? Oh. Cool xD
"Having a bunch of nil indexes" is no problem, because there are already a lot of them in the table.
Yeah true dat.
But will textutils.serialize not have the ones that have been set to nil?
If anything, serialize uses pairs(), which only iterates through non-nil values and their indices.
So yes, serialize will not show nil indices.
620 posts
Location
Holland
Posted 20 April 2013 - 08:49 AM
So yes, serialize will not show nil indices.
Ah that's a shame that's why my program doesn't work :(/>
1688 posts
Location
'MURICA
Posted 20 April 2013 - 10:05 AM
You could try using "false" instead of nil.