Hello everyone! I just need a little bit of help.
I’m trying to spawn random objects. I having al ittle bit of trouble.
I’m assuming I would need tables.
My current spawn code is
[lua]function spawnBoxes()
big1 = display.newImage(“big1.png”)
big1.x = 22 --math.random(22, 150) --playing with random positioning
big1.y = 10
big1.id = “Big 1”
big1V = 0
physics.addBody(big1, --“static”,
{ friction=1, bounce=0.0,density=0.0,
})
big2 = display.newImage(“big2.png”)
big2.x = 63 --math.random(22, 150) --playing with random positioning
big2.y = 10
big2.id = “Big 2”
big2V = 0
physics.addBody(big2, --“dynamic”,
{ friction=5, bounce=0.0, density=0.0,
})
big3 = display.newImage(“big3.png”)
big3.x = --math.random(22, 150) --playing with random positioning
big3.y = 10
big3.id = “Big 3”
big3V = 0
physics.addBody(big3, --“dynamic”,
{ friction=5, bounce=0.0, density=0.0,
})
[/lua]
That works. What it does is drop is simply drop different boxes from the top of the screen.
What I am having a issue with is how can I spawn random boxes fall from the top of the screen.
Basically pick one of those boxes above and randomly spawn it. Each box has specific variables, and id’s.
So I don’t want to merely just change the graphic.
As I’ve said I have been playing with tables, to maybe help solve the problem. I’m kinda lost
this is my Table
[lua]local boxTable = {
{number=1, image=“big1.png”, big1V=1 },
{number=2, image=“big2.png”, big2V=2},
{number=3, image=“big3.png”, big3V=3 },
}
local randN = math.random(1,3)
local boxObj = display.newImage(boxTable[randN].image)[/lua]
This merely spawns a random picture from the table with no characteristics. aka variables.
Is there anyway I can pass those variables for specific boxes into the table ?
Thanks in advance for any help
also can I get a forum name change change to jmorgan or jmorgan88?