S
S
Sergey Mokin2019-11-03 21:56:44
Corona SDK
Sergey Mokin, 2019-11-03 21:56:44

How to fix a bug in Corona SDK?

When I added an event listener to the green circle (boostButton) Corona started throwing an error.
5dbf225165f2f592260333.png
Here is the code:

local score = 0
local boost = 1

display.setDefault( "background", 10/225, 10/225, 10/225)
display.setStatusBar(display.HiddenStatusBar)

local circle = display.newCircle(display.contentCenterX, display.contentCenterY, 50 )

local scoreText = display.newText(score, display.contentCenterX, 90, native.systemFont, 24)

local boostButton = display.newCircle(display.contentCenterX, 400, 30 ):setFillColor(40/225, 60/225, 30/225)--зелёный бустер


local function pushCircle()
  score = score + 1*boost
  scoreText.text = score
end
circle:addEventListener("tap", pushCircle);

local function scoreBoost()
  boost = boost + 1
end
boostButton:addEventListener('tap', scoreBoost)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Lerg, 2019-11-03
@moki002

Remove setFillColor, make it a separate line. It turns out that you are assigning to the boostButton variable not a button object, but the result of the setFillColor function, which is nil, which is what the error tells you about.

D
dollar, 2019-11-04
@dollar

local boostButton = display.newCircle(display.contentCenterX, 400, 30 )
local test = boostButton:setFillColor(40/225, 60/225, 30/225)

In this case, boostButton now contains the result of newCircle, i.e. button link.
But the test variable contains the result of the setFillColor operation, i.e. nil

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question