我是该网站的新手并使用这种语言进行编程......我对该语言有了基本的了解,但我遇到了这个错误:
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