我的代码.............
local physics = require"physics" ----
physics.start()
local storyboard = require("storyboard")
local scene = storyboard.newScene()
function scene:enterScene(event)
city1.enterFrame= scrollCity
Runtime:addEventListener("enterFrame",city1)
city2.enterFrame= scrollCity
Runtime:addEventListener("enterFrame",city2)
city3.enterFrame= scrollCity
Runtime:addEventListener("enterFrame",city3)
city4.enterFrame= scrollCity
Runtime:addEventListener("enterFrame",city4)
Runtime:addEventListener("touch",touchScreen)
end
scene:addEventListener("enterScene",scene)
return scene
但是电晕错误
game.lua:65: attempt to index globall 'city1' (a nil value)
答案 0 :(得分:0)
这很简单。您将city1
定义为局部变量。在函数scene:enterScene(event)
中,它不存在。
答案 1 :(得分:0)
您很可能有范围问题。首先,你应该在当地宣布事情。当你离开当地时,你会成为一个全球性的人,这会让你遇到麻烦而不是解决问题。相反,你应该了解编程的范围。在Storyboard和Composer中,您必须声明要在更高级别的多个函数中访问的变量。本教程解释了所有内容:
https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/