Hi
I’m currently in the process of creating a game which is similar to the helicopter game on blackberry where the goal is to avoid the mines and survive till the timer counts to 0, when this is achieved the game goes to the next level where it will become more difficult. To do this you must touch the screen to make the spaceship fly higher(through applyForce)or let it drop lower(through gravity level) as the ship is a dynamic object. The code for this is below.
[lua]local function flightUp(self,event)
print(“Just before apply force”)
self:applyForce(0,-0.2,self.x,self.y)
print(applyForce)
audio.play(jetSound)
end
function touchS(event)
if event.phase == “began” then
ship.enterFrame = flightUp
Runtime:addEventListener(“enterFrame”, ship)
end
if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, ship)
end
end[/lua]
I then created the level 2 by copying the code for level 1 and changing a few values into a new lua file. and when using almost similar code i get the error “attempt to call method ‘applyForce’(a nil value)” making my spaceship on screen but unable to fly or drop through gravity.
Apart from this error the level2 lua has no errors until "touchS1"is called.
[lua]local function flightUp1(self,event)
print(“This is the flight up1”)
self:applyForce(0,-0.2,self.x,self.y)
end
function touchS1(event)
if event.phase == “began” then
ship.enterFrame = flightUp1
Runtime:addEventListener(“enterFrame”, ship)
end
if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, ship)
end
end[/lua]
Someone help me please