Page 1 of 1

intersect

Posted: Mon Nov 30, 2015 1:27 pm
by problème
Hello,

I would create something like that looks like a gravity.
I have two objects graphics a oval and a rectangle (image the oval is a balloon and the rectangle the floor ^^).
I do this in first for test but my balloon cross the floor.

card script

Code: Select all

on openCard
 set the location of graphic "balloon" to 94,74
 set the location of graphic "floor" to 271,362
end openCard

on somethingLikeGravity
   if no intersect (graphic "balloon", graphic "floor","pixels") then
      set the top of graphic "balloon" to the top of graphic "balloon" +10
      send "somethingLikeGravity" to me in 50 milliseconds
   end if
end somethingLikeGravity
in a button script

Code: Select all

on mouseUp
   if the label of button "button" is "1" then
      set the location of graphic "balloon" to 94,74
      somethingLikeGravity
      set the label of button "button" to "2"
   else 
      repeat for each line aLine in the pendingMessages
         if aLine contains "somethingLikeGravity"  then cancel item 1 of aLine
      end repeat
      set the label of button "button" to "1"
   end if
end mouseUp

Re: intersect

Posted: Mon Nov 30, 2015 3:58 pm
by dunbarx
Probleme.

You must learn to step through your code to find out what is happening. I say this because conceptually your handlers work just fine. You might change the values of your set-up so that only a few iterations through the loop are required to test your thinking.

Anyway, change your handler to this:

Code: Select all

on somethingLikeGravity
   if no intersect (graphic "balloon", graphic "floor","pixels") then
      set the top of graphic "balloon" to the top of graphic "balloon" +1
      send "somethingLikeGravity" to me in 5 milliseconds
   end if
end somethingLikeGravity
See? But more important is what I said above.

Craig Newman

Re: intersect

Posted: Tue Dec 01, 2015 12:59 am
by problème
I changed the values, it still does not work

Re: intersect

Posted: Tue Dec 01, 2015 5:38 am
by dunbarx
When i change the value, it still does not work
Not sure what this means. You must be more speciific.

Anyway, it works for me. What are you seeing?

Craig

Re: intersect

Posted: Tue Dec 01, 2015 6:01 am
by problème
the graphic "balloon" cross the graphic "floor"

Re: intersect

Posted: Tue Dec 01, 2015 6:01 am
by Saman Sjr.
Hi,

Do the important one first like Craig said in his first post, "step through your code to find out what is happening"
It will help you a lot of if you have another problem in the future.

To learn more about debugging :
https://livecode.com/topic/debugging/

regard's
SS

Re: intersect

Posted: Tue Dec 01, 2015 6:37 am
by dunbarx
Probleme.

For me, the "balloon" lands squarely on top of the "floor". Check your handlers again. The issue earlier was that the size of each step by which the balloon descended was simply too large, and by the time the intersection fired, it was below the desired point. As I said, your concept was fine, the fineness of your concept, however, was too coarse.

Craig

Re: intersect

Posted: Tue Dec 01, 2015 3:12 pm
by dunbarx
Probleme.

You know, I never really looked at the way you implemented your task. Not that there is anything wrong with a procedure that works, but what about this? In a button script:

Code: Select all

on mouseUp
   repeat until the bottom of grc 1 > the top of grc 2
      set the loc of grc 1 to item 1 of the loc of grc 1 & "," & item 2 of the loc of grc 1 + 1
      wait 1 --with messages  (should you need this)
   end repeat
end mouseUp
What do you think?

Craig

EDIT.

To make this more readable: on mouseUp
get the loc of grc 1
   repeat until the bottom of grc 1 > the top of grc 2
      add 1 to item 2 of it
      set the loc of grc 1 to it
      wait 1 --with messages  (should you need this)
   end repeat
end mouseUp

Re: intersect

Posted: Tue Dec 01, 2015 9:22 pm
by problème
Hello,
I create a new mainstrack for isolated the code and comment the code i didn't use, and it's work , i don't know why so i restart LiveCode and try again into my real project i change the name of my method "on somethingLikeGravity" by a other name and it's work, i deduce that liveCode didn't take into account my changes.
(the code given by dunbarx work, but i prefer a method which allows to see the fall of the object without freezes execution ^^)

Re: intersect

Posted: Tue Dec 01, 2015 11:12 pm
by dunbarx
Hi.

Code: Select all

the code given by dunbarx work, but i prefer a method which allows to see the fall of the object without freezes execution 
Freezes execution? Do you mean the slight pixel-by-pixel jump? Have you examined the "move" command?

Craig

Re: intersect

Posted: Wed Dec 02, 2015 12:05 pm
by hpsh
i also testet the code, and it works for me.

i just wonder if you can have 2 rectangles, one that is called "floor" and one that is on that cover the rectangle called floor, and that you see, is that the ballon cross the second rectangle?

Re: intersect

Posted: Wed Dec 02, 2015 6:42 pm
by problème
Hello,

I will put pictures on the ball as he falls, with the command " move" that blocks the image scrolling

Re: intersect

Posted: Thu Dec 03, 2015 2:22 am
by hpsh
you can try that :-) its maybe easier to just make a new program, and just copy the code.

it should be possible to find the second rectangle in card inspector, but i am not very good in english :-/

Re: intersect

Posted: Thu Dec 03, 2015 10:47 am
by problème
Hello,

I will try that, thanks for the helps