Having trouble respawning my rock

Please note; I am eleven years old and a novice at Corona.

I created some simple but interesting code for having a raised floor, two buttons (for left and right movement) and a rock that can be rolled around. I plan to create a checkpoint that will allow you to start at a different place than where you first started. The problem is, even after falling the distance that should respawn it, it won’t respawn. Everything else works, but it won’t initiate the function, even if I add an event listener to the rock itself. Here’s the relevant code:

[code]
checkpointX = 240; checkpointY = 100

local function respawn (event)

if ( rock.y < 400 ) then
rock:setLinearVelocity( 0, 0 )
rock.x = checkpointX
rock.y = checkpointY
end
end

rock:addEventListener( “enterFrame”, respawn ) [import]uid: 82408 topic_id: 15219 reply_id: 315219[/import]

Two things show up immediately in you code above.

  1. enterFrame cannot be assigned to an object. Instead of “rock” add the event listener to Runtime.

  2. Your respawn function will enter a never ending loop. When it is triggered it will place the rock at Y + 100, then test the rock.y and equate to it being less than 400 (100 again) and re-fire, placing the rock again at Y + 100, in perpetuity. Change the “” and it may fire correctly. [import]uid: 64596 topic_id: 15219 reply_id: 56229[/import]

[code]

checkpointX = 240; checkpointY = 100

local function respawn (event)

if ( rock.y > 400 ) then – changed less than to greater than
rock:setLinearVelocity( 0, 0 )
rock.x = checkpointX
rock.y = checkpointY
end
end

Runtime:addEventListener( “enterFrame”, respawn ) – changed rock to Runtime

[/code] [import]uid: 64596 topic_id: 15219 reply_id: 56230[/import]

Thanks. It’s hard getting used to that irregular form of Y coordinates. Worked like a charm. [import]uid: 82408 topic_id: 15219 reply_id: 56239[/import]