Page 2 of 4
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 7:34 pm
by chaucer345
When I try this:
Code: Select all
if intersect ((the top of image pUp, Rectangle Rectangle1, 255) then
put true into intersectst
else
put false into intersectst
I get the following error message:
card id 1002: compilation error at line 70 (Expression: missing ')' before factor) near "Rectangle1", char 42
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 7:44 pm
by dunbarx
Hi.
Just takes getting used to this. There is no "rectangle" object or control. There is a property and keyword of that name, but the engine ain't having it.
You likely meant "graphic", and would have written thus:
graphic "rectangle1"
Please quote your literals and your object names.
Craig
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 7:55 pm
by Simon
ummm.... don't forget about the extra open parenthesis.
Simon
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 8:39 pm
by chaucer345
Okay, so this:
Code: Select all
if intersect (the top of image "pUp", graphic "Rectangle1", 255) then
put true into intersectst
else
put false into intersectst
end if
Gives me this error message instead, but only when I try to do the collision, not on compilation:
card id 1002: execution error at line n/a (Chunk: error in object expression) near "172", char 1
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 8:44 pm
by chaucer345
SparkOut wrote: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).
Could you link to explanations of these? They sound very interesting.
((Sorry for the double post, I was trying to edit the first and it got split somehow.))
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 9:00 pm
by Simon
Hi chaucer345,
We're not really magicians here

You'll have to provide more code then just the intersect code, the error could be from many things.
Here is a good site;
https://sites.google.com/a/pgcps.org/livecode/home
Go to "Game Programming" and somewhere in there is a link to lots of intersect based games.
Simon
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 9:07 pm
by chaucer345
Simon wrote:
You'll have to provide more code then just the intersect code, the error could be from many things.
Simon
Ah, the rest of the code is on the previous page. Nothing else has changed and the error message pointed to that line. Sorry about that, I should have been clearer. Also I was only trying to move up, so the other collision handlers should not have been called.
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 10:24 pm
by SparkOut
chaucer345 wrote:Okay, so this:
Code: Select all
if intersect (the top of image "pUp", graphic "Rectangle1", 255) then
put true into intersectst
else
put false into intersectst
end if
Gives me this error message instead, but only when I try to do the collision, not on compilation:
card id 1002: execution error at line n/a (Chunk: error in object expression) near "172", char 1
I think the error here is trying to use one coordinate (the top of the image) in the intersect test. Rather check an intersect of two graphic objects. I can't give much other info as I'm away with nothing but this phone at the moment, but Animation Engine had its own forum here. It's a very well crafted library produced by malte. There are examples galore in the documentation stack.
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 10:32 pm
by chaucer345
SparkOut wrote:
I think the error here is trying to use one coordinate (the top of the image) in the intersect test. Rather check an intersect of two graphic objects. I can't give much other info as I'm away with nothing but this phone at the moment, but Animation Engine had its own forum here. It's a very well crafted library produced by malte. There are examples galore in the documentation stack.
Interesting. That's unfortunate, as I really do need to be able to define if the top, left, right or bottom has intersected something. Does anyone know of a command that can do this?
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 10:42 pm
by Simon
Hi chaucer345,

- 2014-08-06_1441.png (2.67 KiB) Viewed 9191 times
What abut this group?
Simon
Edit: What I mean is if you use the entire control (button shown here) you don't need top,bottom etc.
Edit 2: of course you'd resize them to be what you actually want.
Re: Syntax problem, how is then missing in this statement
Posted: Wed Aug 06, 2014 11:18 pm
by dunbarx
Hi.
Ah. The intersect function deals with some properties of objects, not others. So although there is considerable control over the nature of the pixels that comprise an object, that alpha channel stuff, there is no support at all for, say, the left of an object intersecting with another.
TWO EXERCISES. # 1
You will likely have to roll your own here. For example, if you want to know if the left of button 1 has "intersected" with any part of button 2, you might test to see if the top, center or bottom of that side of the button is within the rect of the other. But the "is within" operator requires a point, not a single value. So although this will give you a valid answer:
answer "100,100" is within the rect of btn 2
this will not:
answer "100" is within the rect of btn 2
So what to do? Well, write a simple function that extracts a bunch of points from any side. If you ask if anyLeftPoint(button 1) is within the rect of button 2, then you are home free. Can you do this? Can you do it in a single robust function that handles all four sides? I hope we are talking about rectangles here, whatever object or graphic is involved. All this becomes much more complex if not.
# 2
What if you detect the intersect, and then determine the relative positions of the two objects? So if you compare the various lefts, rights, tops and bottoms of both, you should be able to determine which side touched the target. (pseudoCode):
Code: Select all
if the left of button 1 is just less than the right of button 2 then youKnowWhichSideHitWhich
This sounds simpler than #1. You should do both.
Write back...
Craig
Re: Syntax problem, how is then missing in this statement
Posted: Thu Aug 07, 2014 3:25 pm
by [-hh]
..........
Re: Syntax problem, how is then missing in this statement
Posted: Thu Aug 07, 2014 8:40 pm
by chaucer345
[-hh] wrote:
The following code should do this, but I didn't test (wrote it down right out of my tired brain). Come back if something is going wrong, because I would like to use it with my kids next sunday. That's why I wrote it down in large, and because it's such a sunny Friday today.
And please, write it also down for one "image" (that is, one group of your 4 images), this was for me essential to learn at my very beginning.
When I tried your code, I got an error message on the following line:
Code: Select all
local myRects = graphic "rectangle1", graphic "rectangle2", graphic "rectangle3", graphic "rectangle4", graphic "rectangle5", graphic "rectangle6", graphic "rectangle7", graphic "rectangle8", graphic "rectangle9", graphic "rectangle10"
Error message:
card id 1002: compilation error at line 14 (Commands: expected ',') near "rectangle1", char 17
I admit I'm not sure what's going on here, has the local variable become like an array in java?
Re: Syntax problem, how is then missing in this statement
Posted: Thu Aug 07, 2014 9:17 pm
by [-hh]
..........
Re: Syntax problem, how is then missing in this statement
Posted: Thu Aug 07, 2014 11:20 pm
by chaucer345
Is there a way to count the number of objects in myRects so that I can put that number into a variable and use it to define the loop count generally?