Next problem with button

Hello everyone, I have another problem with the button. I am trying to make the button ( kprzycisk ) inactive or completely remove after pressing the button. I used the function removeSelf and  isVisible = false probably everywhere, but either nothing happens or I had an error. Could someone advise me where to add and what function to make the button  kprzycisk remove after use. If this is the basis of knowledge and my question is a bit silly I am sorry

local widget = require(“widget”)
local physics = require (“physics”)
physics.start()
physics.setGravity(0,0)

Punkty = 0
PunktyTekst = display.newText("Punkty = " … Punkty, 45, -15, native.systemFont, 15)

local function gprzyciskf (e)
Punkty = Punkty + 1
PunktyTekst.text = “Punkty =” … Punkty
end

local gprzycisk = widget.newButton{
onRelease = gprzyciskf,
defaultFile = “Punkt.png”,
width = 100,
height = 100,
}
gprzycisk.x = display.contentCenterX
gprzycisk.y = display.contentCenterY

local function kprzyciskf (e)
if Punkty >= 5 then
Punkty = Punkty - 5
PunktyTekst.text = “Punkty =” … Punkty
local karabin = display.newImageRect(“karabin.png”, 50, 25)
karabin.y = display.contentCenterY
karabin.x = 30

local function autostrzal()
local pocisk = display.newImageRect(“pocisk.png”, 30, 30)
pocisk.x = karabin.x
pocisk.y = karabin.y
physics.addBody(pocisk, “dynamic”)
transition.to( pocisk, { x= 135, time=200,
onComplete = function() display.remove(pocisk)   

Punkty = Punkty + 1
PunktyTekst.text = “Punkty =” … Punkty
end}
        )
end
timer.performWithDelay( 2000, autostrzal, -1 )
end
end

local kprzycisk = widget.newButton{
onRelease = kprzyciskf,
height = 50,
width = 50,
defaultFile = “orb2.png”,
}
kprzycisk.x = 275
kprzycisk.y = -10
 

Format your code, jeez! :DD

@strusinski

You can use the “<>” button above to format your code or use []  and [/] with “lua” inside - see the “Post Formatting Tips” below.  Often, if your code is unformatted your post will be ignored.

You need a way to reference your button after the onRelease event.  Trying using e.target to identify and remove the button that triggered the onRelease

[lua]

local function kprzyciskf (e)

    local button = e.target  – identify the button

    display.remove(button) ; button = nil – remove the button

    – whatever else you want to do

end

[/lua]

thank you for the advice and solution of the problem! :slight_smile: