Как использовать цикл, чтобы отображать прямоугольник только при соблюдении параметров Corona SDK - PullRequest
0 голосов
/ 10 февраля 2019

Я хотел бы иметь возможность отображать прямоугольник и текст «Добавить 10 деревьев» только после того, как значение whenWork [i] равно 10. В настоящее время кнопка «Добавить 10 деревьев» не работает, пока я не достигну 10 деревьев, но не могузаставить его отображаться только после того, как он достигнет 10 единиц дерева.

-- Test Increment 2
print("restarted")
local width = display.contentWidth
local length = display.contentHeight

local background = display.setDefault("background", 0.1)
local title = display.newText("Wood Game", width/2, -25)
local wood = 0

-- Text
local woodDisplay = display.newText(wood, width/2, 32, nil, 30)
local errorMessage = display.newText("", width/2, -0)
errorMessage:setFillColor(1, 0, 0)

local increments = {1, 10}
local buttons = {"1", "2"}
local buttonY = {100, 150}
local whenWork = {0, 10}

-- Functions
for i = 1, #increments do
  local function addWood(event)
    if event.phase == "ended" and (wood >= whenWork[i]) then
      wood = wood + increments[i]
    elseif event.phase == "ended" and (wood <= whenWork[i]) then
    end
    woodDisplay:removeSelf()
    woodDisplay = display.newText(wood, width/2, 32, nil, 30)
  end
  buttons[i] = display.newRect(width/2, buttonY[i], 150, 25)
  buttons[i]:addEventListener("touch", addWood)
end

local firstButtonText = display.newText("Add 1 Wood", width/2, 100)
local secondButtonText = display.newText("Add 10 Wood", width/2, 150)
firstButtonText:setFillColor(0.2)
secondButtonText:setFillColor(0.2)
...