multidimensional tables/arrays
Posted: Mon Dec 14, 2009 12:10 am
Multidimensional tables/arrays..
Hi, I am trying to grasp the concept of multidimensional tables, so I came up with something to help me understand this better but I dont know if I am on the right track or not.
What I did was make a table called pistols that have 2 guns each with their own tables with values for power, bullet capacity etc.
Now, other questions that I have beside the main question of me being on the right track are...
1. Say I make an empty table for the inventory for my character to hold the guns, and lets say I want to add the revolver from the table called pistols and place it in my characters inventory, will the attributes power and capacity carry over as well since they are in a sub table of "revolver"?
2. And if so, how would I set that up through code?
function load()
font = love.graphics.newFont(love.default_font, 20)
love.graphics.setFont(font)
pistols = {
nineMM = {power = 10, capacity = 24},
revolver = {power = 50, capacity = 6}}
end
function update()
end
function draw()
love.graphics.draw(pistols.revolver.power, 100, 100)
end
Hi, I am trying to grasp the concept of multidimensional tables, so I came up with something to help me understand this better but I dont know if I am on the right track or not.
What I did was make a table called pistols that have 2 guns each with their own tables with values for power, bullet capacity etc.
Now, other questions that I have beside the main question of me being on the right track are...
1. Say I make an empty table for the inventory for my character to hold the guns, and lets say I want to add the revolver from the table called pistols and place it in my characters inventory, will the attributes power and capacity carry over as well since they are in a sub table of "revolver"?
2. And if so, how would I set that up through code?
function load()
font = love.graphics.newFont(love.default_font, 20)
love.graphics.setFont(font)
pistols = {
nineMM = {power = 10, capacity = 24},
revolver = {power = 50, capacity = 6}}
end
function update()
end
function draw()
love.graphics.draw(pistols.revolver.power, 100, 100)
end