Intersect and Grab

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Zephitron
Posts: 21
Joined: Sun Oct 10, 2010 6:04 am

Intersect and Grab

Post by Zephitron » Fri Oct 22, 2010 7:06 am

As part of a game, I'd like the intersect function to be triggered when the user grabs an image and drags it over another image (so that something else will then happen to the grabbed image, etc. ). However it seems as long as the mouse is down it won't be triggered (I'm assuming that's the reason anyway).

If I have a card with two buttons, A and B, the script in A looks like:

on mouseDown
grab me
end mouseDown

and in B reads:

on mouseEnter
if intersect (button "A", button "B") then beep
end mouseEnter

the beep never happens.

Any way around this? I've tried using the grab command with mouseEnter but that won't work because it won't do the grab.

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

Re: Intersect and Grab

Post by bn » Fri Oct 22, 2010 12:37 pm

Hi Zephitron,

I made a little stack that I append that shows one way how to do it.
click on the graphic that shows a label. If you have further questions please feel free to ask.

regards
Bernd
Attachments
objectIntersect.rev.zip
(1.64 KiB) Downloaded 569 times

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Intersect and Grab

Post by WaltBrown » Fri Oct 22, 2010 6:26 pm

Nice stack, Bernd, I learned a lot from that.
Walt
Walt Brown
Omnis traductor traditor

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

Re: Intersect and Grab

Post by bn » Fri Oct 22, 2010 6:59 pm

Walt,

thank you.

regards
Bernd

Zephitron
Posts: 21
Joined: Sun Oct 10, 2010 6:04 am

Re: Intersect and Grab

Post by Zephitron » Tue Oct 26, 2010 10:02 pm

That's great Bernd. I don't understand it, but it works. (I don't know how you whip this stuff up so fast!).

I was thrown off the first line:
local sCheckIntersect = false, sAlliDs, sMyID, sAllColors

because visually it looked like the list "false, sAlliDs, sMyID, sAllColors" is all associated with the "sCheckIntersect =" part of the statement, plus I've been used to putting variables on separate lines. But when I back and looked at it, I realized it was just a standard list of variables where one of them was "sCheckIntersect = false". I'm a visual thinker. I rearranged it so the "sCheckIntersect = false" is last.

That's as far as I got with is – been working on other things.
However after a quick perusal of the code, I would hazard to surmise that the key difference here is the use of "on mouseMove", which I never thought of.

I can't wait to look into it when I have time.

Thank so much!

(I'll share my game stack when get the intersect and maybe a another feature or two working).

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

Re: Intersect and Grab

Post by bn » Wed Oct 27, 2010 12:32 am

Eric,
this is where you put the list of script local variables, outside of any other handler and I put them alway at the top.
I prepend all the script local variable with an s so I can see in the scipts that I am referring to a script local variable instead of a local variable that only lives inside a handler. I prepend them with t like tSomeThing.

The cool thing is that when you declare a script local variable you can initialize them to a value. That is where the "sCheckIntersect = false" comes from.
Script local variables did not exist in Hypercard and they are extremly useful. They often replace global variables, which I avoid for various reasons. I have come to use them quite liberally. They persist between runs but not when you close the app.

And at times I also dont put them as list into one row but list them vertically. But then that takes more space = more scrolling.
I would hazard to surmise that the key difference here is the use of "on mouseMove"
first, I put that into my book of English...
You got it. That was the whole point of the stack, the rest was just decoration.

regards
Bernd

Zephitron
Posts: 21
Joined: Sun Oct 10, 2010 6:04 am

Re: Intersect and Grab

Post by Zephitron » Fri Oct 29, 2010 12:54 am

I see how it works now. I've posted about my animation stack in another thread - under Rich Media.

I understood about the variables and their placement. I've started prepending them with s, as per your enlightening examples. I didn't know that about HyoerCard and script local variables, but now that I reflect, indeed I don't remember a distinction: there were just global and local.

I'm happy my over-grown vocabulary (from wasting too many years at a university) at least enlarges someone else's a bit. You native tongue is Deutsch? I am of mostly German stock. My grandparents on my mother's side came from Northern Germany (family name Bartell), and My father was a mix of German/Prussian/English-Irish/Who Knows.

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

Re: Intersect and Grab

Post by bn » Fri Oct 29, 2010 3:57 pm

Hi Eric,

see my reply there
I'm happy my over-grown vocabulary (from wasting too many years at a university) at least enlarges someone else's a bit. You native tongue is Deutsch? I am of mostly German stock. My grandparents on my mother's side came from Northern Germany (family name Bartell), and My father was a mix of German/Prussian/English-Irish/Who Knows.
Yes, my native language is German. And I like these idioms/sophisticated ways of saying "I guess" or somesuch. It sounds so British to me and it makes me smile. One of my favorites is "Dr. Livingstone, I presume?".
If you use vocabulary like that then "I hazard to surmise that those too many years at a university where spend in the humanities?"

regards
Bernd

Zephitron
Posts: 21
Joined: Sun Oct 10, 2010 6:04 am

Re: Intersect and Grab

Post by Zephitron » Fri Oct 29, 2010 6:05 pm

You surmise correctly: philosophy, then some visual art at the end.

I've watched British comedies ..probably by the thousands over the years, and have been to Britain for a couple of weeks. If some one offered me a job over there I'd go. Really enjoyed the conversation and people.

Danke

Post Reply