Hello All - just discovered Corona and quite intrigued by it and have started through the tutorials.
I have a C/VB/Java/Pascal background … and understand Arrays, Hashtables, Vectors etc However, I’m struggling to understand how the following piece of code is working. It is from the Bullet sample app. In it they create a 7x8 set of sodacans:
for i = 1, 7 do
for j = 1, 8 do
cans[i] = display.newImage( "soda\_can.png", 190 + (i\*24), 220 - (j\*40) )
physics.addBody( cans[i], { density=0.2, friction=0.1, bounce=0.1} )
end
end
“cans” is a table. They iterate through two loops. In most languages, would have filled the cans table with a line as follows:
cans[i,j] = display.newImage( "soda\_can.png", 190 + (i\*24), 220 - (j\*40) )
However, they just reference the [i] index into the table.
How is it that through every iteration of the ‘j’ loop, its not overwriting the current ‘cans[i]’ value with the new assignment. Somehow, it seems to be adding to the table with every iteration
I’m guessing its some sort of behavior in Lua tables but I havent been able to quite figure it out.
Appreciate the help,
Chris [import]uid: 12082 topic_id: 4197 reply_id: 304197[/import]