Hi, I’m a beginner, unfortunately on the internet aren’t many guides about the Lua language in Polish, and I’m not a master of English I have a question about button operation. I created a code that after pressing the button is to reduce the amount of myScore by 5 points, but when I click the button nothing happens. Only after collecting points, myScore is changing (if I click twice before and collect 1 orb(points) myScore = -9)
.
.
.
local myScore = 0
local tapText = display.newText(myScore, 0, 19, native.systemFont, 25)
–orb collection function (collecting points) :
local function trackOrbs(obj)
myScore = myScore + 1
tapText.text = myScore
obj:removeSelf();
end
local function spawnOrb()
local orb = display.newImageRect(“moneta.png”, 15, 15)
orb.x =mRand(50, _W-50); orb.y = 230;
physics.addBody(orb, “static”, {radius = 1})
function orb:collision(e)
if (e.phase == “began”) then
trackOrbs(self);
end
return true;
end
orb:addEventListener(“collision”, orb);
end
tmr = timer.performWithDelay(20, spawnOrb, total_orbs)
**local function btnf(event)
myScore = myScore - 5
end
local btn = widget.newButton {
label=“Buy”,
onRelease = btnf,
fontSize = 20,
width = 190
}**
I also don’t understand why it shows me an error when, in the button’s parameters, it adds for example height = 30
thank you very much for every answer!!!