Hi ConallChloride,
when addressing objects in Livecode you ALWAYS need to add the TYPE of object!
##Correct:
...
set the loc of image "canvas.png" to (random(500),0)
...
## NOT correct:
set the width of "canvas.png" to 128
set the height of "canvas.png" to 32
...
## Correct: (img = abbreviation for image)
set the width of IMG "canvas.png" to 128
set the height of IMG "canvas.png" to 32
...
Some general hints!
Whe using lots of nested IF THEN clauses, see, if you can start the other way round!
I mean do not check for TRUE conditions, but for the opposite first, so we can LEAVE the function/handler immediately in that case!
That will shorten your IFs and make them MUCH more readable.
Example, your finction "checkalien", does what it should, but is hardly readable:
Code: Select all
function checkalien
if there is an image "shooter" then
if the top of image "canvas.png" >= the bottom of image "shooter" and the top of image "canvas.png" <= the top of image "shooter" then
if the left of image "canvas.png" >= the left of image "shooter" and the right of image "canvas.png" <= the right of image "shooter" then
return true
end if
end if
end if
end checkalien
Here my variation, which does exactly the same but is readable and understandable at ONE glance:
Code: Select all
function checkalien
if there is NOT an image "shooter" then
## I think this should ALSO be returned!
return false
end if
if the top of image "canvas.png" < the bottom of image "shooter" and the top of image "canvas.png" > the top of image "shooter" then
return false
end if
if the left of image "canvas.png" < the left of image "shooter" and the right of image "canvas.png" > the right of image "shooter" then
return true
end if
return false
end checkalien
Best
Klaus