Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
chaucer345
- Posts: 23
- Joined: Thu Jul 24, 2014 8:08 pm
Post
by chaucer345 » Tue Aug 05, 2014 10:13 pm
Hi guys, I get an error message when I try to compile the code below. The compiler claims there is an if statement missing a then, even though the then is present. I came in from java so I'm still new to this semi-english syntax.
Code: Select all
if the top of image pUp OR the top of image pDown OR the top of image pLeft OR the top of image pRight and Rectangle1 OR Rectangle2 OR Rectangle3 OR Rectangle4 OR Rectangle5 OR Rectangle6 OR Rectangle7 OR Rectangle8 OR Rectangle9 OR Rectangle10 intersect then
put false into intersectst
else
put true into intersectst
end if
I can't figure out what's wrong, do you have any advice?
-
DavJans
- Posts: 275
- Joined: Thu Dec 12, 2013 4:21 pm
Post
by DavJans » Tue Aug 05, 2014 10:29 pm
Looks like the format is wrong
try this
if intersect( <object1> , <object2> ) then
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10305
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Aug 05, 2014 10:31 pm
Hi.
What is the story with that "intersect" thingie at the end of that outrageous first line?
Anyway, that is your culprit. Sometimes the engine complains, like a petulant child, and you are not sure whether it is hungry or wet. The best way to figure these things out is to comment from right to left, re-inserting a "then" as you go, until you get no error after compiling.
Craig Newman
-
chaucer345
- Posts: 23
- Joined: Thu Jul 24, 2014 8:08 pm
Post
by chaucer345 » Tue Aug 05, 2014 10:53 pm
dunbarx wrote:Hi.
What is the story with that "intersect" thingie at the end of that outrageous first line?
Anyway, that is your culprit. Sometimes the engine complains, like a petulant child, and you are not sure whether it is hungry or wet. The best way to figure these things out is to comment from right to left, re-inserting a "then" as you go, until you get no error after compiling.
Craig Newman
Thank you for the advice!
That was me miss-understanding the syntax... and yeah, I know that statement is kind of silly. It's basically me checking for collisions of the player sprite with all of the rectangles on the screen. The theoretically working version?
Code: Select all
if intersect ((the top of image pUp OR the top of image pDown OR the top of image pLeft OR the top of image pRight), (Rectangle1 OR Rectangle2 OR Rectangle3 OR Rectangle4 OR Rectangle5 OR Rectangle6 OR Rectangle7 OR Rectangle8 OR Rectangle9 OR Rectangle10)) then
put false into intersectst
else
put true into intersectst
end if
On a side note if you know a more efficient way to check for intersections like this I'd be very glad to hear it.
Edit: That code appears to throw the following error:
card id 1002: execution error at line n/a (Chunk: error in object expression) near "false", char 1
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Tue Aug 05, 2014 11:11 pm
Hi chaucer345,
I think it would be best to start here;
Code: Select all
if intersect (the top of image pUp,Rectangle1) then
if that works for you then add the rest 1 by 1 testing each time.
So, you have 4 images colliding with 10 rectangles.
Do you need to use "top"? Wouldn't any intersect work for you? Yes, yes I know it's the top of the image because this is a vertical slider. but any intersect would do wouldn't it?
OK is this game like a single rocket/bird/person and a bunch of falling or moving asteroids/pipes/pigs?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
chaucer345
- Posts: 23
- Joined: Thu Jul 24, 2014 8:08 pm
Post
by chaucer345 » Tue Aug 05, 2014 11:25 pm
Simon wrote:Hi chaucer345,
I think it would be best to start here;
Code: Select all
if intersect (the top of image pUp,Rectangle1) then
if that works for you then add the rest 1 by 1 testing each time.
So, you have 4 images colliding with 10 rectangles.
Do you need to use "top"? Wouldn't any intersect work for you? Yes, yes I know it's the top of the image because this is a vertical slider. but any intersect would do wouldn't it?
OK is this game like a single rocket/bird/person and a bunch of falling or moving asteroids/pipes/pigs?
Simon
The four images are four pictures of the player moving in an upwards, downwards, left and right direction. The rectangles I'm checking against are meerly the walls of the room that I want the player to stop at.
I think the full code for the card might be useful here:
Code: Select all
local intersectst
local intersectsb
local intersectsl
local intersectsr
on preOpenCard
show image pRight
hide image pLeft
hide image pUp
hide image pDown
put false into intersectst
put false into intersectsb
put false into intersectsl
put false into intersectsr
end preOpenCard
on arrowKey nMessage
if nMessage is "down" then
checkIntersects
if intersectsb is false then
set the top of image pUp to the top of image pUp + 10
set the top of image pDown to the top of image pDown + 10
set the top of image pLeft to the top of image pLeft + 10
set the top of image pRight to the top of image pRight + 10
end if
hide image pUp
hide image pLeft
hide image pRight
show image pDown
else if nMessage is "up" then
checkIntersects
if intersectst is false then
set the top of image pUp to the top of image pUp -10
set the top of image pDown to the top of image pDown -10
set the top of image pLeft to the top of image pDown - 10
set the top of image pRight to the top of image pRight -10
end if
hide image pDown
hide image pLeft
hide image pRight
show image pUp
else if nMessage is "left" then
checkIntersects
if intersectsl is false then
set the left of image pUp to the left of the image pUp - 10
set the left of image pDown to the left of the image pDown - 10
set the left of image pLeft to the left of the image pLeft - 10
set the left of image pRight to the left of the image pRight - 10
end if
hide image pUp
hide image pDown
hide image pRight
show image pLeft
else if nMessage is "right" then
checkIntersects
if intersectsr is false then
set the left of image pUp to the left of image pUp + 10
set the left of image pDown to the left of image pDown + 10
set the left of image pLeft to the left of image pLeft + 10
set the left of image pRight to the left of image pRight + 10
end if
hide image pUp
hide image pDown
hide image pLeft
show image pRight
end if
end arrowKey
command checkIntersects
if intersect ((the top of image pUp OR the top of image pDown OR the top of image pLeft OR the top of image pRight), (Rectangle1 OR Rectangle2 OR Rectangle3 OR Rectangle4 OR Rectangle5 OR Rectangle6 OR Rectangle7 OR Rectangle8 OR Rectangle9 OR Rectangle10)) then
put true into intersectst
else
put false into intersectst
end if
if intersect ((the bottom of image pUp OR the bottom of image pDown OR the bottom of image pLeft OR the bottom of image pRight), (Rectangle1 OR Rectangle2 OR Rectangle3 OR Rectangle4 OR Rectangle5 OR Rectangle6 OR Rectangle7 OR Rectangle8 OR Rectangle9 OR Rectangle10)) then
put true into intersectsb
else
put false into intersectsb
end if
if intersect ((the left of image pUp OR the left of image pDown OR the left of image pLeft OR the left of image pRight), (Rectangle1 OR Rectangle2 OR Rectangle3 OR Rectangle4 OR Rectangle5 OR Rectangle6 OR Rectangle7 OR Rectangle8 OR Rectangle9 OR Rectangle10)) then
put true into intersectsl
else
put false into intersectsl
end if
if intersect ((the right of image pUp OR the right of image pDown OR the right of image pLeft OR the right of image pRight), (Rectangle1 OR Rectangle2 OR Rectangle3 OR Rectangle4 OR Rectangle5 OR Rectangle6 OR Rectangle7 OR Rectangle8 OR Rectangle9 OR Rectangle10)) then
put true into intersectsr
else
put false into intersectsr
end if
end checkIntersects
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Tue Aug 05, 2014 11:33 pm
I think you should group your images for the player.
Now lets just talk about a 4 walled room.
Code: Select all
if intersect(group "player", image "wall",255) then
Assuming the center of the room is transparent (alpha 0) then every time the "player" tries to move out of the box the if/then is true.
If you need help with transparencies and such just ask.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
chaucer345
- Posts: 23
- Joined: Thu Jul 24, 2014 8:08 pm
Post
by chaucer345 » Tue Aug 05, 2014 11:42 pm
Simon wrote:I think you should group your images for the player.
Now lets just talk about a 4 walled room.
Code: Select all
if intersect(group "player", image "wall",255) then
Assuming the center of the room is transparent (alpha 0) then every time the "player" tries to move out of the box the if/then is true.
If you need help with transparencies and such just ask.
Simon
I noticed the group objects thing, but I haven't been able to figure out how to label grouped objects. How is it done?
Also, it's kind of important for me to be able to tell if the player collided with a wall from the top, bottom left or right because I need to make sure that if they hit something from one direction they can't move further in that direction, but ensure they can still move in other directions (flypaper syndrome is a very cruel taskmaster). Do you have any advice for adapting the system to accommodate that?
Also, what's the 255 for?
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Tue Aug 05, 2014 11:57 pm
...from one direction they can't move further in that direction
Ok, yes then you need the four images, still I think you want to group them together to keep them moving in unison. Here is a lesson on grouping;
http://lessons.runrev.com/m/4071/l/1303 ... iple-cards
They use the old Application Browser, not the Project Browser but they both work.
But is "top" still needed?
Also, what's the 255 for?
Ahhh I thought you'd ask that. From the Dictionary;
alpha value - An integer between 0 and 255 which specifies a threshold that the alpha value of each pixel must be greater than or equal to in order to be counted during calculation of the intersect.
It's the opacity/transparency of an image, are you familiar with those terms?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
chaucer345
- Posts: 23
- Joined: Thu Jul 24, 2014 8:08 pm
Post
by chaucer345 » Wed Aug 06, 2014 12:00 am
I am familiar, I've seen the word pixels used in similar statements to avoid blank space causing collisions.
Last edited by
chaucer345 on Wed Aug 06, 2014 12:46 am, edited 1 time in total.
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Wed Aug 06, 2014 12:21 am
Hi chaucer345,
No need to quote my entire post... really I'm still just right here.
Simply, 255 means a solid pixel, 0 is completely transparent and then there are all the ones in between.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
chaucer345
- Posts: 23
- Joined: Thu Jul 24, 2014 8:08 pm
Post
by chaucer345 » Wed Aug 06, 2014 12:48 am
Sorry about that! Quote Yanked.
Still, does the objects not being grouped explain the error message?
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Wed Aug 06, 2014 1:08 am
Still, does the objects not being grouped explain the error message?
I dunno...
Tell me what happens when you use just a single image and a single rectangle.
Then 1 image and 2 rects, then 2 images and 2 rects.
Maybe you can't use an "and" or "or" in the function. If you tell me then we'll both know.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
JackieBlue
- Posts: 32
- Joined: Sun Jun 22, 2014 2:37 am
Post
by JackieBlue » Wed Aug 06, 2014 3:18 am
What about Switch Case? Any time you have a multiple (well, more than 2) cases I use a Switch Case (Select Case in other languages).
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Wed Aug 06, 2014 6:38 am
I think this is a great learning exercise, but I can't stop myself from mentioning Animation Engine and looking up constrainRectangular (and other constrain variants).
For the complex if...then I agree a switch construction would be much clearer. And agree with the advice to help resolve the boolean AND/OR cases one by one - and it helps me to put parentheses round each case to clearly see what the engine will see. Every one of those needs to resolve to a true or false state, and while constructing, splitting those parenthesised cases onto separate lines in your script editor could help.