Lua 编写的 Mod 无法正常工作

我有一个针对游戏 Factorio 的 Mod,最初是由其他人编写的,我进行了一些修改,并尝试使其保持更新。但是在最新的 Factorio 版本中,它会提示以下错误:

    __DriveAssist__/control.lua:3:尝试对字段'player'进行索引(一个空值)

相关的代码如下:

    script.on_event(defines.events.on_tick, function(event)
    if game.tick%20 == 0 then
        if game.player.vehicle and game.player.vehicle.valid and game.player.vehicle.type == "car" then
            if game.player.gui.left.frameDA == nil then
                frameDA = game.player.gui.left.add{type = "frame", name = "frameDA", direction = "horizontal"}
                local tab = frameDA.add{type ="table", name = "tableDA", colspan = 3}
                tab.add{type = "button", name = "buttonDANorthWest", caption = "NW"}
                tab.add{type = "button", name = "buttonDANorth", caption = "N"}
                tab.add{type = "button", name = "buttonDANorthEast", caption = "NE"}
                tab.add{type = "button", name = "buttonDAWest", caption = "W"}
                tab.add{type = "label", name = "DAblank4", caption = " "}
                tab.add{type = "button", name = "buttonDAEast", caption = "E"}
                tab.add{type = "button", name = "buttonDASouthWest", caption = "SW"}
                tab.add{type = "button", name = "buttonDASouth", caption = "S"}
                tab.add{type = "button", name = "buttonDASouthEast", caption = "SE"}
            end
        elseif game.player.gui.left.frameDA then
                game.player.gui.left.frameDA.destroy()
        end
    end
 end)

    script.on_event(defines.events.on_gui_click, function(event)
    if event.element.name == "buttonDANorth" then
        game.player.vehicle.orientation = 0.0
--      game.player.print("北")
elseif event.element.name == "buttonDANorthWest" then
        game.player.vehicle.orientation = 0.875
--      game.player.print("西北")
  elseif event.element.name == "buttonDAWest" then
        game.player.vehicle.orientation = 0.75
--      game.player.print("西")
elseif event.element.name == "buttonDASouthWest" then
        game.player.vehicle.orientation = 0.625
--      game.player.print("西南")
    elseif event.element.name == "buttonDASouth" then
        game.player.vehicle.orientation = 0.5
--      game.player.print("南")
elseif event.element.name == "buttonDASouthEast" then
        game.player.vehicle.orientation = 0.375
--      game.player.print("东南")
    elseif event.element.name == "buttonDAEast" then
        game.player.vehicle.orientation = 0.25
--      game.player.print("东")
elseif event.element.name == "buttonDANorthEast" then
        game.player.vehicle.orientation = 0.125
--      game.player.print("东北")
--  else
--      game.player.print(event.element.name or "元素缺少名称!")
  end
end)
点赞