Help with arrays, I think

Ok let me start by saying that I am a Lua noob, and in the past have self taught myself obj c, so I am not a pro by any straetch of the imagination.

I have been trying to learn Lua by online docs and tutorials but also messing about with the sample projects, here on corona.

Recently i have been playing with the SimplePool demo because it seems to get quite complicated for a noob like me, but I now have one question, and I am puzzled.

to create the triangle of balls you use

local n = 0  

and then you inplement

 n = n + 1  

I understand how this makes a triangle, by adding one ball to each row

But, what I have been trying to figure out is how would you make a shape like a diamond for example, I started with this

n = n + 1 elseif n = 4 then n = n - 1

but of course this did not work, so then I tried to set up an array

local n = {1, 2, 3, 4, 3, 2, 1}

And as you may have guessed that did not work, but then that got me thinking, what would i do if i wanted the balls set up like this 1,2,1,4,5,2,1…

And now my head hurts after a few solid hours of reading online docs and messing about with code.

Many thanks and if you can help a noob it would be much appreciated
Chris [import]uid: 10697 topic_id: 3730 reply_id: 303730[/import]

You were on the right track with the array/table based approach. Just use a For loop to iterate over your table to read the number of balls for each row.

Something like:

[code]

local i
local n
local layout = {1,2,3,4,3,2,1}

for i = 1,#layout do
n = layout[i]
print (“Row “…i…” has “…n…” balls”)
end [import]uid: 9064 topic_id: 3730 reply_id: 11379[/import]