cannot transition frome game.lua to restart.lua

i attempted to reference peng in function but i just get the same error for peng that i got for event

local function activatePengs(peng,event)

   peng:applyForce(0, -45, peng.x, peng.y)

end

local function touchScreen(event)

    peng = event.target

– print(“touch”)

    if event.phase == “began” then

        peng.enterFrame = activatePengs

        Runtime:addEventListener(“enterFrame”, peng)

    end

    if event.phase == “ended” then

        Runtime:removeEventListener(“enterFrame”, peng)

    end

end

Change this:

[lua]

local function activatePengs (event)

[/lua]

You were still trying to pass peng to the listener. The first (only) parameter on an enterFrame listener is always event. If you call it peng, then now peng isn’t your object anymore within that function, peng is event and doesn’t have a function called applyForce.

Try this example:

[lua]
local dogfood = “Winalot”
local catfood = “Whiskers”

local buyCatfood = function (catfood)

print ("In function: "…catfood)
end

buyCatfood(dogfood)
print ("Outside function: "…catfood)

[/lua]

The above example shows you passing dogfood to the catfood function. Even if you call the parameter catfood in the function, it will still actually be acting on dogfood. You could call it geoff, it will still be dogfood.

Outside of the function, catfood will refer to catfood again.

This is the same as calling event ‘peng’ in the listener parameter list.

You also need to remove peng = event.target from touchScreen.

Doing this overwrites peng with event.target.

And the biggest piece of advice is still to slow down and work through tutorials. The error messages are there for a reason, they tell you exactly went wrong and where, but you need to know what is right before that makes any sense…

the confusing part is when i go from start.lua to game.lua, everything is fine but going from restart.lua to game.lua is what causes the error

and if i click play fast enough after the collision happens it works aagain

is it possible there’s a problem in my restart.lua?