Hi all, I have code to move the enemy ship in my game, however I cannot get it to move from the top of the card to the bottom. Spawning of the enemy works, but movement down does not.
on moveAlien
if moveEnemy = FALSE then
movealien
end if
set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)
if the top of image "alienEnemy" >= 400 then
delete image"alienEnemy"
put false into moveEnemy
//put (lives - 1) into lives
put false into alienEnemy
put false into moveEnemy
end if
end moveAlien
This is what I have so far. Any help is appreciated!
Update: Movement now works due to adding in the line "send "moveAlien" to me in 5 milliseconds", however when the enemy is shot I get an error with the first line in this sub-rutine "set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)". Can anyone help?
So basically, when my bullet intersects with the alien the image is deleted. This can happen up to four times before I'm taken into my code due to a problem with the line "set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)"
on moveAlien
if moveEnemy = FALSE then
return false
end if
if game = false then
return false
end if
set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)
if the top of image "alienEnemy" >= 590 then
delete image"alienEnemy"
put false into moveEnemy
put (lives - 1) into lives
put false into alienEnemy
send gameloop to me
end if
send moveAlien to me in 5 millisecs
end moveAlien
Even after you delete the alienEnemy, you still send the message "moveAlien". Could it be that message that gets you the next time you go in that code and try to move an alienenemy that has been deleted?
set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)
if the top of image "alienEnemy" >= 590 then
delete image"alienEnemy"
put false into moveEnemy
put (lives - 1) into lives
put false into alienEnemy
send gameloop to me
else
send moveAlien to me in 5 millisecs
end if