---------------
--Spawn enemies
---------------

local function spawnEnemies()

local enemy = {}

for l = 1, 2, 1 do
enemy[l] = display.newImage("enemy.png", true)
enemy[l].x = screenW * 0.5 - 10
enemy[l].y = ball.height - 10


physics.addBody( enemy[l], {friction = 0.3, gravity = .0000001, bounce = 0.3} )

myJoint = physics.newJoint( "distance", ball, enemy[l], ball.x, ball.y, enemy[l].x, enemy[l].y )

end
end

local randomNumber1 = math.random(5000)
local myTimer = timer.performWithDelay (randomNumber, spawnEnemies, 0)


--I need to use the enemy[l] variable in the following function but the debugger says it doesn't --recognize it.

---------------
--Enemy Bullets
---------------
local function shootE()

local ebullet = {}

for n = 1, 2, 1 do


 ebullet[n] = display.newImage("ebullet.png", true)
ebullet[n].isBullet = true
local state = ebullet[n].isBullet

ebullet[n]:applyForce( 500, 2000, enemy[l].x, enemy[l].y)

end

end

local eshootTimer = timer.performWithDelay( 5000, shootE, 0)

Add a code snippet to your website: www.paste.org