Hello,
I’m having an issue. I am trying to get objects to spawn when another object is touched based on the position of the user’s finger. After the first object is touched, I would like it to be removed, leaving only the spawned objects. How do I do this? Below is the code I set up for the original object.
[blockcode] local removeLarge = function( event )
local t = event.target
local phase = event.phase
if (health_up ~= true) then
if “began” == phase then
t:removeSelf() – destroy object
starting_blocks = starting_blocks + 1
_score = _score + SCORE_LRG
score.text = _score
createSplitblock()
winLose()
end
end
– Stop further propagation of touch event
return true
end
[/blockcode]
Here is the code I set up for the spawned objects
[blockcode]
function createSplitblock( event )
local phase = event.phase
if “ended” == phase then
local splitblock = display.newImageRect(“images/s_boulder.png”, 35, 35);
localGroup:insert(splitblock)
splitblock.x = event.x
splitblock.y = event.y
physics.addBody(splitblock, {density = 0.3, friction = 0.3})
splitblock:setLinearVelocity(0,1)
splitblock.name = “small block”
splitblock:addEventListener(“touch”, removeSmall)
splitblock:addEventListener(“collision”, smallblockCollision )
end
return true
end
[/blockcode]
I am receiving the following error
Runtime error
/Users/Username/Desktop/Corona/level1.lua:270: attempt to index local ‘event’ (a nil value)
stack traceback:
[C]: ?
/Users/Username/Desktop/Corona/level1.lua:270: in function ‘createSplitblock’
I believe it’s referring to the second function I posted. Can anyone point me in the right direction or tell me a better way to do this? Any help would be greatly appreciated.
Thanks,
[import]uid: 47722 topic_id: 13053 reply_id: 313053[/import]
[import]uid: 3826 topic_id: 13053 reply_id: 47914[/import]