попытка индексировать местный - PullRequest
1 голос
/ 10 апреля 2020

Я получаю сообщение об ошибке:

libs/timer.lua:144: attempt to index local 'subject' (a nil value)

Traceback

libs/timer.lua:144: in function 'tween_collect_payload' libs/timer.lua:158: in function 'tween' classes/Button.lua:64: in function 'listenKey' states/menu.lua:35: in function 'keypressed' main.lua:58: in function <main.lua:57> [C]: in function 'xpcall'

Я думаю, что есть проблема, но я не знаю, где именно:

классы / кнопки. lua

function Button:listenKey(key)
  local action = self.buttons[self.currentPosition][2]
  local prev = self.currentPosition - 1
  local nex = self.currentPosition + 1
  moveRight = function(buttonPos)
    timer.tween(.5, buttonPos, {[3] = 150}, "in-out-linear")
  end
  if key == "w" or key == "up" then
    sounds.menu.move:stop()
    sounds.menu.move:play()
    if self.currentPosition > 1 then
      -- here goes error  
      timer.tween(.5, self.buttons[nex], {[3] = 150}, "in-out-linear")
    end
    moveRight(self.buttons[self.currentPosition])
    self.currentPosition = math.max(1, self.currentPosition - 1)
  elseif key == "s" or key == "down" then
    sounds.menu.move:stop()
    sounds.menu.move:play()
    if self.currentPosition <= lume.count(self.buttons) then
      -- and here goes error 
      timer.tween(.5, self.buttons[prev], {[3] = 150}, "in-out-linear")
    end
    moveRight(self.buttons[self.currentPosition])
    self.currentPosition = math.min(lume.count(self.buttons), self.currentPosition + 1)
  elseif key == "return" then
    sounds.menu.move:stop()
    sounds.menu.enter:stop()
    sounds.menu.enter:play()
    action()
  end
end

Использование hump.timer, библиотек среднего класса. Пробовал много вариантов получения следующей и предыдущей позиций, но в любом случае я не могу получить право "lua -way"

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...