Creating Games? Developing something for fun?
	Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
			
		
		
			- 
				
																			
								ConallChloride							 
									
		- Posts: 6
 		- Joined: Wed Nov 12, 2014 1:42 pm
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by ConallChloride » Wed Dec 17, 2014 1:09 pm
			
			
			
			
			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.
Code: Select all
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!  
 
Many thanks, Conall
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								ConallChloride							 
									
		- Posts: 6
 		- Joined: Wed Nov 12, 2014 1:42 pm
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by ConallChloride » Wed Dec 17, 2014 1:27 pm
			
			
			
			
			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?
Thanks, Conall
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								Klaus							 
									
		- Posts: 14255
 		- Joined: Sat Apr 08, 2006 8:41 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by Klaus » Wed Dec 17, 2014 2:04 pm
			
			
			
			
			Hi Canall,
sorry, don't get this?
WHAT condition in your handler refers to the fact that an ALIEN might be "dead"?
And WHAT error do you get? 
We surely need a tad more info! 
 
Best
Klaus
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								ConallChloride							 
									
		- Posts: 6
 		- Joined: Wed Nov 12, 2014 1:42 pm
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by ConallChloride » Thu Dec 18, 2014 9:59 am
			
			
			
			
			Hi Klaus
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)"
I'm not too sure on how I can fix this.
The whole block is 
Code: Select all
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
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								Klaus							 
									
		- Posts: 14255
 		- Joined: Sat Apr 08, 2006 8:41 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by Klaus » Thu Dec 18, 2014 1:23 pm
			
			
			
			
			Hi Conall,
hm, still not sure I get it 
 
Maybe addind another if then clause will do the trick?
Code: Select all
on moveAlien
   if there is NOT an img "alienEnemy" then
     exit moveAlien
   end if
   ...
?
Best
Klaus
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								Newbie4							 
						- VIP Livecode Opensource Backer

 			
		- Posts: 332
 		- Joined: Sun Apr 15, 2012 1:17 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by Newbie4 » Fri Dec 19, 2014 4:44 am
			
			
			
			
			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?
Try this
Code: Select all
  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
 
			
			
									
									Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/