Help with List and a function?

Hello,
I need some help.

I want to spawn new enemys with a timer. This is what i have now:

[lua]local spawn = {}
local n = 1
function newenemy()

local random = math.random(1,800)
spawn[n] = display.newImage(“media/pos.png”)

spawn[n].x= random/2;spawn[n].y= 40;

localGroup:insert(spawn[n]);

spawn[n]:addEventListener(“touch”, delete);

transition.to( spawn[n], { time=2000, y=enemy.y+230, x=_W/2 } )

end

timer.performWithDelay(1000, newenemy)
timer.performWithDelay(1000, newenemy)[/lua]
If i try it it give a error:
[text]
Runtime error
/Users/gzijlstra/Desktop/App/First Project/game.lua:87: attempt to index global ‘enemy’ (a nil value)
stack traceback:
[C]: ?
/Users/gzijlstra/Desktop/App/First Project/game.lua:87: in function
?: in function <?:215>
[/text]
Whats wrong?

This is not all of the code! [import]uid: 120506 topic_id: 22682 reply_id: 322682[/import]

The error is saying that the ‘enemy’ object does not exist. Does the code to create that object exist, and if so has it been run before this function is called? [import]uid: 93133 topic_id: 22682 reply_id: 90463[/import]

Hello, I found my problem after I posted this, but I still need help. The problem I have is on the function delete, if the things are in a list how can I delete them if they get touched?

Thanks Gjosse [import]uid: 120506 topic_id: 22682 reply_id: 90476[/import]

transition.to( spawn[n], { time=2000, y=enemy.y+230, x=_W/2 } )

probably should read:

transition.to( spawn[n], { time=2000, y=spawn[n].y+230, x=_W/2 } )

In addition you never increment n, so they all are writing over each other in spawn[1].

[import]uid: 19626 topic_id: 22682 reply_id: 90479[/import]