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!
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.
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
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
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.
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
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.
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.
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:
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
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 ^^)
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?