Can't get "enemy" character appear

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SammL1
Posts: 5
Joined: Thu Jun 05, 2014 11:12 am

Can't get "enemy" character appear

Post by SammL1 » Tue Nov 11, 2014 3:25 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Can't get "enemy" character appear

Post by Mark » Tue Nov 11, 2014 3:42 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SammL1
Posts: 5
Joined: Thu Jun 05, 2014 11:12 am

Re: Can't get "enemy" character appear

Post by SammL1 » Thu Nov 13, 2014 2:57 pm

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.

catalinanesia
Posts: 83
Joined: Sun Feb 16, 2014 10:08 pm

Re: Can't get "enemy" character appear

Post by catalinanesia » Thu Nov 13, 2014 3:04 pm

Hi Samm,
You can attach the stack to the forum post, make sure you are making it a *.zip file first.

Regards!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Can't get "enemy" character appear

Post by Mark » Thu Nov 13, 2014 3:20 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Can't get "enemy" character appear

Post by Newbie4 » Thu Nov 20, 2014 3:05 am

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)
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/

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Can't get "enemy" character appear

Post by Mark » Thu Nov 20, 2014 8:38 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Games”