Thanks very much
Intersect not triggering
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Intersect not triggering
Ah, okay!
Thanks very much
Thanks very much
Re: Intersect not triggering
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
Re: Intersect not triggering
Hi tehkst,
1. welcome to the forum
2. "I have problem running..." is not a helpful error description and not everyone has that namely stack at hand!
So please describe what does not work and post the script(s).
Thanks!
Best
Klaus
1. welcome to the forum
2. "I have problem running..." is not a helpful error description and not everyone has that namely stack at hand!
So please describe what does not work and post the script(s).
Thanks!
Best
Klaus
Re: Intersect not triggering
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
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/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: Intersect not triggering
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: &
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: &
Re: Intersect not triggering
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
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
Re: Intersect not triggering
Hi tehkst,
instead of
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
instead of
tryif intersect (button("sheep"&x), graphic"pen","255") is false and intersect(button"sheep"&x),group"groupControls","0") is false then
Code: Select all
if intersect (button("sheep"&x), graphic"pen","255") is false and intersect(button("sheep"&x),group"groupControls","0") is false thenThis 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
