Could you elaborate a little bit more please? I am very new.
Using this code as an example maybe?
local physics = require("physics") physics.start() physics.setGravity( 0, 5) local eggplant = display.newImageRect( scene.perRunGroup, "images/eggplant.png", 50, 50, display.contentCenterX, display.contentCenterY, 30) eggplant.x = 70 eggplant.y = 100 physics.addBody(eggplant, "dynamic", {radius = 25, friction = .4, density = 0.0035, bounce = 0.8}) eggplant.gravityScale = 0.5 eggplant.collisionType = "eggplant" -------------------------Add eggplant button local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) if event.phase == "ended" and eggplant.alpha ~= 1 then eggplant.alpha = 1 physics.addBody(eggplant) end if ( "ended" == event.phase ) then print( "Button was pressed and released" ) end end local addeggplant = widget.newButton( { width = 80, height = 40, defaultFile = "images/level.png", overFile = "images/level.png", label = "", onEvent = handleButtonEvent } ) -- Center the button addeggplant.x = 150 addeggplant.y = 20 -- Change the button's label text addeggplant:setLabel( "Add" ) sceneGroup:insert(addeggplant) -------------Remove eggplant button local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) if event.phase == "ended" and eggplant.alpha ~= 0 then eggplant.alpha = 0 physics.removeBody(eggplant) end if ( "ended" == event.phase ) then print( "Button was pressed and released" ) end end local removeeggplant = widget.newButton( { width = 80, height = 40, defaultFile = "images/level.png", overFile = "images/level.png", label = "", onEvent = handleButtonEvent } ) -- Center the button removeeggplant.x = 40 removeeggplant.y = 20 -- Change the button's label text removeeggplant:setLabel( "Remove" ) sceneGroup:insert(removeeggplant)
Here I have an eggplant and a remove/add button for the eggplant.
So how would I add a counter to each of the buttons so that the add button will add 3 eggplants max.