Intersect not triggering

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

Sekoshiba
Posts: 31
Joined: Thu Sep 26, 2013 8:23 pm

Re: Intersect not triggering

Post by Sekoshiba » Mon Dec 16, 2013 8:34 pm

Ah, okay!

Thanks very much :D

tehkst
Posts: 2
Joined: Fri Jan 03, 2014 9:57 am

Re: Intersect not triggering

Post by tehkst » Fri Jan 03, 2014 10:00 am

Hi... Anyone can help me with the intersect code on the sheep herder in lesson 2? I copied the codes from the lessons and have problem running. I think there is problem with the code in Line 17 on the intersect

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Intersect not triggering

Post by Klaus » Fri Jan 03, 2014 12:34 pm

Hi tehkst,

1. welcome to the forum :D

2. "I have problem running..." is not a helpful error description and not everyone has that namely stack at hand! 8)
So please describe what does not work and post the script(s).

Thanks!


Best

Klaus

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

Re: Intersect not triggering

Post by Newbie4 » Fri Jan 03, 2014 4:30 pm

A couple of notes regarding the previous posts. (These are from experience working with live code and have carried through many versions of LiveCode.) If I am wrong or the latest versions have changed the rules, anyone is welcome to correct me. But this is what I have noticed:

1. In general, the set command (i.e. set the loc of image "enemy1" to tX,tY) is better than using the move command. It is more instantaneous (no delay). You can read more in the dictionary. This is especially noticeable with images because of the greater pixel density.
2. The intersect command sometimes needs a 3rd parameter (i.e. intersect(image "enemy1", image "player1", 255) as a number or something like "opaque pixels". See the dictionary for more details. It used to be required but later versions of LiveCode has made it not always needed.
3. It is better to use a button or other object than an image. I think it is because an image can have so many more pixels and is harder to check (and move for that matter). Create a button. Then note the ID number of the image and set the icon number of the button to that ID. It produces the same visual effect but seems to work better in the code.
This also has the advantage of easily changing the "look" of the button by just changing the icon # on the button. You can have your character change into something else (change the ID from an image of a turtle to that of a rabbit) or add visual effects (change the icon to the image of an explosion, then quickly back to the original image so it "flashes" briefly) and other neat effects that you might come up with.
4. When you jump to another card, make that "go to" the last bit of code in that handler. Otherwise the handler will finish up executing and trying to move objects that are not on the new card. As an alternative, you can "exit" the handler right after the "go to card "x". (This is good if you have multiple go to's in the handler.
5. I generally do not like using too many "send" message commands because they sometimes come back to bite you. (You go on to other code and that message is still out there to execute or it continues to keep sending messages when you don't want it to.) You should add a flag (boolean variable) and check it in the code that sends the message. That way you can stop the messages from being sent when you go to a different card.
6. Sometimes a message has to be 'cancelled'. See the dictionary for the cancel command and there are code examples at the bottom at this link: https://sites.google.com/a/pgcps.org/li ... ng-targets

I hope this helps you and sort of explains a bit more about how LiveCode works
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/

tehkst
Posts: 2
Joined: Fri Jan 03, 2014 9:57 am

Re: Intersect not triggering

Post by tehkst » Mon Jan 06, 2014 4:56 am

Thanks for your reply.

The error that I am getting is as follows:

compiling at 11:54:48 AM
Type intersect: two objects are required
Object: card id 1002
Line: if intersect (button("sheep"&x), graphic"pen","255") is false and intersect(button"sheep"&x),group"groupControls","0") is false then
Hint: &

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

Re: Intersect not triggering

Post by dunbarx » Mon Jan 06, 2014 5:09 am

Hi,

Not sure about the lessons, but the error is sort of telling you either that one of the objects does not exist, or that the reference itself is broken, and does not resolve properly to an object that may well exist.

So before you execute that line, check to see if everything is ready. For example:

If there is a button ("sheep" & x)
if there is a graphic "pen"

That sort of thing. See if these are really there. If they are not, put them there. If the construction of the reference itself is broken, fix it.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Intersect not triggering

Post by bn » Mon Jan 06, 2014 2:24 pm

Hi tehkst,

instead of
if intersect (button("sheep"&x), graphic"pen","255") is false and intersect(button"sheep"&x),group"groupControls","0") is false then
try

Code: Select all

	if intersect (button("sheep"&x), graphic"pen","255") is false and intersect(button("sheep"&x),group"groupControls","0") is false then
the difference is the second intersect where you reference button (sheep&x), one bracket seems to be missing and Livecode can not resolve sheep&x

This is assuming there is a button (sheep&x) as Craig pointed to.
One trick is to double click the error message and Livecode hilights the beginning of the error. At times this helps to see the error.

Kind regards
Bernd

Post Reply