Page 1 of 1

Can't get "enemy" character appear

Posted: Tue Nov 11, 2014 3:25 pm
by SammL1
When I run the code for game I am creating for my Advanced Higher i can't get the enemy ship to appear on screen and i don't know what is causing this to happen, or rather not happen.

Code: Select all

on createalien
   
   create invisible image "canvas.png"
   set the loc of image "canvas.png" to (random(500),0)
  
   //Undecied on size yet, Decide on size
   
   set the width of "canvas.png" to 128
   set the height of "canvas.png" to 32
   
   movealien
end createalien

on movealien
   
   if the visible of "canvas.png" is false then set the visible of image "canvas.png" to true
   set the top of image "canvas.png" to (the bottom of image"canvas.png" + 2)
   if the top of image "canvas.png" >= 582 then
      delete image"canvas.png"
      put (lives - 1) into lives
   else
      if checkalien() is true then
         delete image "canvas.png"
         --         hide group "enemy" with visual effect dissolve very fast 
         set the loc image "shooter" to (327,289)
         send startalien to me in random(1000) milliseconds
         exit movealien
      end if
   end if
   
   if there is an image "canvas.png" then send movealien to me in 4 milliseconds
   
end movealien
This is the section of code I am trying to get to work and spawn in enemies.

Re: Can't get "enemy" character appear

Posted: Tue Nov 11, 2014 3:42 pm
by Mark
Hi,

"canvas.png" is only the name of the new image control. You may as well call it "strawberry" or "pkghalrx_", it doesn't matter. Before or after you create the image, you have to set the filename or the text of the image. If you have an image "canvas.png" in your stack already, you might do this:

Code: Select all

create img
put it into myImg
set the text of myImg to the text of img "canvas.png"
Or if you have the picture in a file next to your stack, you might use

Code: Select all

set the itemDel to slash
put item 1 to -2 of the effective filename of this stack & "/canvas.png" into myPath
set the path of the templateImage to myPath
create img
put it into myImg
Variations on these scripts are also possible.

Kind regards,

Mark

Re: Can't get "enemy" character appear

Posted: Thu Nov 13, 2014 2:57 pm
by SammL1
Hi Mark,

Thanks for code snippets, but when I try to implement them still nothing happens, I have several instances of the image called "canvas.png" on other cards in the stack but even with the snippets in place I can't seem to get anything to happen regarding the spawning "enemies".

Is there any way for me to send you a copy of the stack so that you can look over the content to try and find out what is going wrong?

many thanks, Samm.

Re: Can't get "enemy" character appear

Posted: Thu Nov 13, 2014 3:04 pm
by catalinanesia
Hi Samm,
You can attach the stack to the forum post, make sure you are making it a *.zip file first.

Regards!

Re: Can't get "enemy" character appear

Posted: Thu Nov 13, 2014 3:20 pm
by Mark
Hi,

I never download stacks from the forum because it takes me too much time, which I should reserve for my clients.

Do you have another handler that calls the createalien handler?

Kind regards,

Mark

Re: Can't get "enemy" character appear

Posted: Thu Nov 20, 2014 3:05 am
by Newbie4
This is a shot in the dark (I did not analyze your code in detail) but shouldn't the line here:

on movealien
if the visible of "canvas.png" is false then set the visible of image "canvas.png" to true
set the top of image "canvas.png" to (the bottom of image"canvas.png" + 2)
...

be:

on movealien
if the visible of image "canvas.png" is false then set the visible of image "canvas.png" to true
set the top of image "canvas.png" to (the bottom of image"canvas.png" + 2)

Re: Can't get "enemy" character appear

Posted: Thu Nov 20, 2014 8:38 am
by Mark
You're right, newbiw, but Samm also says that just nothing happens. It looks like his handlers don't run and he doesn't even see the errors he should be seeing.

Kind regards,

Mark