Code: Select all
blocks = {}
blocks["block1"] = {}
All help is appreciated. Thanks.
Code: Select all
blocks = {}
blocks["block1"] = {}
Code: Select all
for key, value in pairs(blocks) do
-- do stuff with the stuff from blocks
end
Code: Select all
blocks = {}
blocks["block1"] = {}
blocks["block1"].name = "block1"
blocks["block1"].funct = function() print("Debug") end
blocks["block2"] = {}
blocks["block2"].name = "block2"
blocks["block2"].funct = function() print("Debug2") end
By the way, indexing with strings can be done just with the "." , like you also did later. This is exactly the same as your version:MicroMacro wrote:Yeah, I might need a better example. Here's what the full block tables look like:
How would I makea for loop run through both blocks and run both of their functions?Code: Select all
blocks = {} blocks["block1"] = {} blocks["block1"].name = "block1" blocks["block1"].funct = function() print("Debug") end blocks["block2"] = {} blocks["block2"].name = "block2" blocks["block2"].funct = function() print("Debug2") end
Code: Select all
blocks = {}
blocks.block1= {}
blocks.block1.name = "block1"
blocks.block1.funct = function() print("Debug") end
blocks.block2 = {}
blocks.block2.name = "block2"
blocks.block2.funct = function() print("Debug2") end
Code: Select all
blocks = {
block1 = {
name = "block1",
funct = function() print"Debug" end
},
block2 = {
name = "block2",
funct function() print"Debug" end
}
}
Code: Select all
blocks = {
{
name = "block1",
funct = function() print"Debug" end
},
{
name = "block2",
funct function() print"Debug" end
}
}
Code: Select all
for I = 1, #blocks do print( blocks[ I ].name ) end
You could use the general ent table, and just keep track of the blocks in a seperate table, as well:Ref wrote:To beat a dead horse, how about simply:and use a simple 'for' loop?Code: Select all
blocks = { { name = "block1", funct = function() print"Debug" end }, { name = "block2", funct function() print"Debug" end } }
Code: Select all
for I = 1, #blocks do print( blocks[ I ].name ) end
Code: Select all
local blocks = {}
local blockproto = {}
function blockproto:onCreate(id) -- when you create an entity, call entity:onCreate(id)
blocks[self] = id
end
function blockproto:onDestroy() -- when you destroy an entity, call entity:onDestroy()
blocks[self] = nil
end
-- you should get the picture from this
Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests