V
V
Vladimir Kulikov2020-04-03 10:19:04
Corona SDK
Vladimir Kulikov, 2020-04-03 10:19:04

Why is there an error in corona sdk?

local widget = require("widget")
-- фон приложения
display.setDefault("background", 37/255, 39/255, 46/255)
  
-- цвет текста по умолчанию
display.setDefault("fillColor", 0)


number = 9;
numberMinusButton = widget.newButton {
  shape = 'roundedRect', -- форма кнопки
  raidus = 5, -- радиус скругления уголков
  width = 60, height = 60, -- размеры кнопки
  left = 19, top = 90, -- положение кнопки
  fontSize = 40, -- размер шрифта
  fillColor = { default={ 150/255 }, over={ 76/255 } }, -- цвет кнопки
  labelColor = { default={ 0 }, over={ 1 } }, -- цвет текста
    label = 'adf', -- текст на кнопке
    -- нажатие на кнопку
    onPress =  function(event)
        if number ~= 0 then
            number = number - 1;
            print(number)
      mynumber.text = number
        end
    end
}

local options = 
{
  parent = numberGroup,
  text = number,
    x = display.contentCenterX, 
    y = 53,
  font = native.systemFont, 
  fontSize = 50,
}
 
local mynumber2 = display.newText( options )
mynumber2.y = 70
local mynumber = display.newText( options )
mynumber:setFillColor( 255, 255, 255 )

Error when clicking on the button
https://i.imgur.com/lzXXQPc.png

Hello, what causes an error when clicking on the button?
When you click, the text should change, the number should decrease.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Lerg, 2020-04-03
@it_proger29

mynumber needs to be raised higher in the file, higher than the button, otherwise the text object is simply not visible to the button. Or use forward declaration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question