Syntax problem, how is then missing in this statement

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

Re: Syntax problem, how is then missing in this statement

Post by chaucer345 » Wed Aug 06, 2014 7:34 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Syntax problem, how is then missing in this statement

Post by dunbarx » Wed Aug 06, 2014 7:44 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Syntax problem, how is then missing in this statement

Post by Simon » Wed Aug 06, 2014 7:55 pm

ummm.... don't forget about the extra open parenthesis.

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

Re: Syntax problem, how is then missing in this statement

Post by chaucer345 » Wed Aug 06, 2014 8:39 pm

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

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

Re: Syntax problem, how is then missing in this statement

Post by chaucer345 » Wed Aug 06, 2014 8:44 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Syntax problem, how is then missing in this statement

Post by Simon » Wed Aug 06, 2014 9:00 pm

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

Re: Syntax problem, how is then missing in this statement

Post by chaucer345 » Wed Aug 06, 2014 9:07 pm

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.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Syntax problem, how is then missing in this statement

Post by SparkOut » Wed Aug 06, 2014 10:24 pm

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.

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

Re: Syntax problem, how is then missing in this statement

Post by chaucer345 » Wed Aug 06, 2014 10:32 pm

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?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Syntax problem, how is then missing in this statement

Post by Simon » Wed Aug 06, 2014 10:42 pm

Hi chaucer345,
2014-08-06_1441.png
2014-08-06_1441.png (2.67 KiB) Viewed 7542 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.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Syntax problem, how is then missing in this statement

Post by dunbarx » Wed Aug 06, 2014 11:18 pm

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Syntax problem, how is then missing in this statement

Post by [-hh] » Thu Aug 07, 2014 3:25 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 4:14 pm, edited 2 times in total.
shiftLock happens

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

Re: Syntax problem, how is then missing in this statement

Post by chaucer345 » Thu Aug 07, 2014 8:40 pm

[-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?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Syntax problem, how is then missing in this statement

Post by [-hh] » Thu Aug 07, 2014 9:17 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 4:14 pm, edited 1 time in total.
shiftLock happens

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

Re: Syntax problem, how is then missing in this statement

Post by chaucer345 » Thu Aug 07, 2014 11:20 pm

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?

Post Reply