시도

2014-10-15 4 views
1

그래서 내가 onCollision 이벤트의 사용하여 게임을 좀하고 있어요 :시도

local function onCollision(event) 
    if event.phase == "began" and gameIsActive == true then 
     local obj1 = event.object1; 
     local obj2 = event.object2; 

     if obj1.name == "bill" then 
     if  obj2.name == "rocks" then gameover() 
     elseif obj2.name == "" then 
     end 
    end 
    end 
end 
Runtime:addEventListener("collision", onCollision) 

을하지만, 처음 예상대로 내가 코드가 작동하는 약간의 문제가 실행 시간이지만 게임을 다시 시작합니다.이 오류가 발생합니다.

File: game.lua 
Line: 649 
Attempt to call global 'gameover' (a table value) 

stack traceback: game.lua:649: in function <game.lua:643> ?: in function <?:221> 

649 = if obj2.name == "rocks" then gameover() 
643 = local function onCollision(event) 

어떤 생각일까요?

gameover 기능 :

function gameover() 

rightTAP:removeEventListener("tap", movePLAYERr) 
leftTAP:removeEventListener("tap", movePLAYERl) 

timer.pause(spawnBits) 
timer.pause(Rockspawner1) 
timer.pause(tmrscore) 
timer.pause(updateScoretimer) 
timer.pause(spawnDinosControll) 

audio.pause(drillingChannel) 

drillbg.isVisible = false 
scoreText.isVisible = false 

Restartg = display.newText("Restart", 0, 0,nil, 20) 
Restartg:setFillColor(0, 0, 0) 
screenGroup:insert(Restartg) 
Restartg.x= display.contentWidth/2 
Restartg.y= display.contentHeight/2 + 160 

Restartg:addEventListener("tap", RestartGame1) 

end 

답변

-1

모든 런타임 리스너를 제거해야 재시작시 gameover 기능

3

오류 메시지는 분명하다 : 당신은 gameover를 호출하려고하며 테이블 값 대신 함수의 값을 갖는다. 당신은 다음과 같은 오류가 발생합니다 : gameover = {}; gameover().

즉, gameover 함수를 올바르게 정의하지 않았거나 스크립트의 어느 곳에서 값 gameover을 덮어 쓰지 못했습니다.

+0

질문에 gameover 기능을 추가 –

0

함수 객체가있는 경우 선언 할 때 사용하는 키를 호출 할 수 있습니다.

el = {} 

print(el) 
table: 0x7f8fe9e003f0 

el.f1 = function() 
print('hola') 
end 


el.f1() 
hola 
0

에 "transition.pause (thisRock)"를 추가하여 해결했습니다. 그렇지 않으면 그들은 여전히 ​​듣고 있으며 이미 제거 된 방법으로 이어지기 때문에 오류를 유발할 수 있습니다. RestartGame1에서

장소를 :

Runtime:removeEventListener("collision", onCollision)