我对这个网站和语言编程都很陌生.我对这门语言有了基本的理解,我犯了这个错误:
assertion failed!
stack back:
[C]: ?
[C]: in function 'assert'
?: in function 'getOrCreateTable'
?: in function 'addEventListener'还有更多的台词,但你可以看到照片。
这是我的代码,位于它说要去的区域:
title:addEventListener("tap",title)
how:addEventListener("tap",how_fun)
function how_fun:tap( event )
local how_img = display.newImage("how.png",0,0)
how_img:addEventListener("tap" ,home_switch)
end
local function home_switch( event )
local title = display.newImage(mainGroup, "title.png",0,0)
local how = display.newImage(mainGroup, "how_button.png",0,0)
end我不知道哪里出了问题..。这个代码就在那里,所以如果我点击上面的图像,它会做我想做的.但我在how_img:addEvent中有个错误..。区域!
如果有任何问题,我会很乐意回答他们!
以下是整个代码:
-- Hide status bar
display.setStatusBar(display.HiddenStatusBar)
-- main game group
mainGroup = display.newGroup()
local title = display.newImage(mainGroup, "title.png",0,0)
local how = display.newImage(mainGroup, "how_button.png",70,200)
function title:tap()
-- sets settings for cats
local cat_health = 10
local cat_hunger = 10
local cat_voice = 10
local cat_hygiene = 10
local your_score = 0
local cat = display.newImage(mainGroup, "bg.png",0,0)
local food = display.newImage(mainGroup, "food.png",0,0)
local bath = display.newImage(mainGroup, "bath.png",200,0)
local hunger = display.newText(mainGroup,"Hunger "..cat_hunger.."/10",display.contentWidth/2+15,display.contentHeight-40, native.systemFont, 18)
hunger:setTextColor(255,255,255)
local Score = display.newText(mainGroup,"Your Score: "..your_score,20,display.contentHeight-40, native.systemFont, 18)
Score:setTextColor(255,255,255)
local health = display.newText(mainGroup,"Health "..cat_health.."/10",display.contentWidth/2+15,display.contentHeight-65, native.systemFont, 18)
health:setTextColor(255,255,255)
local hygiene = display.newText(mainGroup,"hygiene "..cat_hygiene.."/10",20,display.contentHeight-65, native.systemFont, 18)
hygiene:setTextColor(255,255,255)
function food:tap( event )
if (cat_hunger<10) then
cat_hunger = cat_hunger+1
hunger.text = "Hunger "..cat_hunger.."/10"
end
return true
end
local function trigger()
if (cat_hunger>0) then
cat_hunger = cat_hunger-1
end
if (cat_hygiene>0) then
cat_hygiene = cat_hygiene-1
end
hunger.text = "Hunger "..cat_hunger.."/10"
hygiene.text = "Hygiene "..cat_hygiene.."/10"
return true
end
local function your_score_func()
your_score = your_score+1
Score.text = "Your Score: "..your_score
end
local function health_func( event )
if (cat_hunger==2) then
cat_health = cat_health-1
health.text = "Health: "..cat_health.."/10"
end
if (cat_hunger==1) then
cat_health = cat_health-2
health.text = "Health: "..cat_health.."/10"
end
if (cat_hunger==0) then
cat_health = cat_health-3
health.text = "Health: "..cat_health.."/10"
end
if (cat_hygiene==2) then
cat_health = cat_health-1
health.text = "Health: "..cat_health.."/10"
end
if (cat_hygiene==1) then
cat_health = cat_health-2
health.text = "Health: "..cat_health.."/10"
end
if (cat_hygiene==0) then
cat_health = cat_health-3
health.text = "Health: "..cat_health.."/10"
end
if (cat_health<1) then
local bkgd = display.newImage("over_bg.png",0,0)
end
return false
end
function bath:tap( event )
if (cat_hygiene<10) then
cat_hygiene = cat_hygiene+1
hygiene = "hygiene "..cat_hygiene.."/10"
end
return true
end
timer.performWithDelay(4000, trigger,0)
timer.performWithDelay(2000, your_score_func,0)
timer.performWithDelay(3000, health_func,0)
bath:addEventListener("tap",bath)
food:addEventListener("tap",food)
timer.performWithDelay(1000, music_loop)
local function music_loop( event )
audio.play(main_mus)
timer.performWithDelay(1000, music_loop,0)
end
end
title:addEventListener("tap",title)
how:addEventListener("tap",how_fun)
function how_fun:tap( event )
local how_img = display.newImage("how.png",0,0)
how_img:addEventListener("tap" ,home_switch)
end
local function home_switch( event )
local title = display.newImage(mainGroup, "title.png",0,0)
local how = display.newImage(mainGroup, "how_button.png",0,0)
end发布于 2013-09-17 23:38:00
没有名为how_fun的对象。
你应该改变:
function how_fun:tap( event )
local how_img = display.newImage("how.png",0,0)
how_img:addEventListener("tap" ,home_switch)
end至
function how:tap( event )
local how_img = display.newImage("how.png",0,0)
how_img:addEventListener("tap" ,home_switch)
endhttps://stackoverflow.com/questions/18861208
复制相似问题