Right now I have this code in my gameLoop(gets called every frame):
[code]
if event.time - timeLastEnemy >= math.random(100, 1000) then
– Randomly position it on the top of the screen
names = {“rock1”,“rock1”,“rock1”,“rock1”,“rock2”,“rock2”,“rock3”,“rock4”,“rock5”,“rock6”,“rock7”}
name = names[math.random(11)]
enemy = display.newImage(name…".png")
halfEnemyWidth = enemy.contentWidth * .5
enemy.x = math.random(halfEnemyWidth, display.contentWidth - halfEnemyWidth)
enemy.y = -enemy.contentHeight
– This has to be dynamic, making it react to gravity, so it will
– fall to the bottom of the screen.
physics.addBody(enemy,physicsData:get(name))
enemy.name = “enemy”
enemiesLayer:insert(enemy)
timeLastEnemy = event.time
end
if enemy.y > 480 then
print(“hiiii”)
enemy:removeSelf()
end
(code stops here)
Then the enemies do not get removed (i know becuz my hiiii message isnt being displayed)
The error is “attempt to index global ‘enemy’(a nil value)”
Please help, Jason [import]uid: 8335 topic_id: 12572 reply_id: 312572[/import]