2013-05-14 2 views
0

Я получаю сообщение об ошибке:ОШИБКА: попытка индекса глобального объекта нилъ значение: коронный SDK

Ошибка выполнения ... п-stylr \ Документы \ коронные проекты \ happy_day \ game.lau: 50 : попытка индекса глобальной «city1» (нилъ значение)

Мой код выглядит следующим образом:

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 
+3

, пожалуйста, задайте свой вопрос удобным названием. У большинства людей, задающихся здесь, есть проблема и не может найти решение. – kelunik

ответ

1

Просто объявить local city1 вне функции createScene и создать city1 как:

local city1; 

function scene:createScene(event) 
    -- your code for localGroup and bg 

    city1 = display.newImage("bild.png") -- just create city1 as this 

    -- do the rest of your code 
end 

Если возникла ошибка с повторением других городов (city2, 3 или 4), сделайте одинаковый метод для всех этих.

Сохраните кодировку ................ :)

Смежные вопросы