Creating clones of the same physics body with different values tied to the same lever

Hello!
I’m brand new to the Lua language and pretty much programming in general, been getting along great but have hit a roadblock unfortunately.
I’m trying to create 100 physics bodies, all the same shape, colour etc. (basically clones of one archetype), but each with a different value or tag that I can reference towards, however without having to put for instance 100 chunks containing :

local newCard = display.newRoundedRect(80, 50, 150, 400, 3)
newCard.strokeWidth = 3
newCard:setFillColor(154, 80, 44)
newCard:setStrokeColor(0, 0, 0)
physics.addBody(newCard, “dynamic”, { filter=newCardCollisionFilter} )
newCard:addEventListener(“touch”, gameUI.dragBody )

into my code. Help on finding a way around this would be absolutely fantastic and greatly appreciated.
Thanks very much,
Ryan [import]uid: 67571 topic_id: 11514 reply_id: 311514[/import]

make a pseudo class containg that and then isantiate it in a loop… [import]uid: 50154 topic_id: 11514 reply_id: 41770[/import]

Very sorry photos, complete beginner here, any chance you could go into some more detail? It would be greatly appreciated!
Cheers,
Ryan [import]uid: 67571 topic_id: 11514 reply_id: 41778[/import]

you can do something like below

[lua]local tags = { “1”, “2”, “3” } – you put your values/tags here

for i = 1, #tags do
local newCard = display.newRoundedRect(80, 50, 150, 400, 3)
newCard.strokeWidth = 3
newCard:setFillColor(154, 80, 44)
newCard:setStrokeColor(0, 0, 0)
physics.addBody(newCard, “dynamic”, { filter=newCardCollisionFilter} )
newCard:addEventListener(“touch”, gameUI.dragBody )
newCard.tag = tags[i]
end[/lua] [import]uid: 48521 topic_id: 11514 reply_id: 41805[/import]

Hello chinmay.patil!
Thank you very much for your help! Unfortunately I’ve hit another roadblock, I’m trying to add a joint to each of the flash cards that come up, e.g. I want the cards to pivot around a single point, but when I do this :

local tags = { “1”, “2”, “3” } – you put your values/tags here

for i = 1, #tags do
local flashCard = display.newRoundedRect(80, 50, 150, 400, 3)
flashCard.strokeWidth = 3
flashCard:setFillColor(255, 255, 255)
flashCard:setStrokeColor(0, 0, 0)
physics.addBody(flashCard, “dynamic”, { filter=flashCardCollisionFilter} )
flashCard:addEventListener(“touch”, gameUI.dragBody )
flashCard.tag = tags[i]
end

cardJoint = physics.newJoint( “pivot”, flashCard, lever, 150, 70 )
cardJoint.isLimitEnabled = true – (boolean)
cardJoint:setRotationLimits( -45, 0 )
a1, a2 = cardJoint:getRotationLimits()
the lever isn’t having any effect anymore. If you could help that would be great!
Cheers,
Ryan [import]uid: 67571 topic_id: 11514 reply_id: 41871[/import]

Sorry for the double-post, got the problem sorted!
Thank you so much for the help,
Cheers!
Ryan [import]uid: 67571 topic_id: 11514 reply_id: 41913[/import]