android - ERROR: attempt to index global object a nil value: corona SDK -
i'm getting error:
runtime error ...n-stylr\documents\corona projects\happy_day\game.lau:50: attempt index global 'city1' (a nil value)
my code follows:
function scene:createscene(event) local screengroup = self.view local background = display.newimage("background1.jpg") local city1 = display.newimage("bild.png") city1:setreferencepoint(display.bottomleftreferencepoint) city1.x = 0 city1.y = 640 city1.speed = 1 local city2 = display.newimage("bild.png") city2:setreferencepoint(display.bottomleftreferencepoint) city2.x = 1136 city2.y = 640 city2.speed = 1 local city3 = display.newimage("build2.png") city3:setreferencepoint(display.bottomleftreferencepoint) city3.x = 0 city3.y = 640 city3.speed = 2 local city4 = display.newimage("build2.png") city4:setreferencepoint(display.bottomleftreferencepoint) city4.x = 1136 city4.y = 640 city4.speed = 2 end function scene:enterscene(event) runtime:addeventlistener("touch", touchscreen) print(city1) 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) end
just declarelocal city1
outside createscene
function , create city1
as:
local city1; function scene:createscene(event) -- code localgroup , bg city1 = display.newimage("bild.png") -- create city1 -- rest of code end
if error occurs reffering other cities(city2 ,3 or 4), same methode those.
keep coding................ :)
Comments
Post a Comment