[comp.sys.mac.hypercard] if there is ... at xx,yy

kem@h.gp.cs.cmu.edu (Kenneth Mohnkern) (03/28/91)

I guess HC2.0's "there is" doesn't have the ability to check if 
there's an object at a certain point. The manual doesn't cover
"there is" very well. I think it's only mentioned in a table of
functions (or commands? properties?) I tried "If there is a bg 
btn at 442,42 then beep". I got an error message.

Is there another way around this? I'd like to look at a specific 
location and see if there's a button there without looking at
every button and comparing its loc with the desired loc.

I know if there's a cool way to do this I'll find it here.

Thanks,
	ken

-- 

ken mohnkern#the robotics institute#carnegie mellon univ#pittsburgh pa

leue@galen.crd.ge.com (Bill Leue) (03/28/91)

In article <12497@pt.cs.cmu.edu> kem@h.gp.cs.cmu.edu (Kenneth Mohnkern) writes:
>I guess HC2.0's "there is" doesn't have the ability to check if 
>there's an object at a certain point. The manual doesn't cover
>"there is" very well. I think it's only mentioned in a table of
>functions (or commands? properties?) I tried "If there is a bg 
>btn at 442,42 then beep". I got an error message.
>
>Is there another way around this? I'd like to look at a specific 
>location and see if there's a button there without looking at
>every button and comparing its loc with the desired loc.
>
>I know if there's a cool way to do this I'll find it here.

It's pretty easy.  First, find out if the object exists.  Next, if
it exists, get its location properties and test them against your
requirements.

if there is a <object> then
  get the TopLeft of <object>
  -- or some other location property
  if it is <your coordinates> then
    -- the object exists at the desired location
  else
    -- it exists, but not at the desired location
  end if
else
  -- it doesn't exist at all
end if

-Bill Leue
leue@crd.ge.com

kem@h.gp.cs.cmu.edu (Kenneth Mohnkern) (03/28/91)

I ask:
) I guess HC2.0's "there is" doesn't have the ability to check if 
) there's an object at a certain point. 
)  [...]
) 				I'd like to look at a specific 
) location and see if there's a button there without looking at
) every button and comparing its loc with the desired loc.
) 
) I know if there's a cool way to do this I'll find it here.
) 

Bill Leue answers:
) It's pretty easy.  First, find out if the object exists.  Next, if
) it exists, get its location properties and test them against your
) requirements.
) 
) if there is a <object)  then
)   get the TopLeft of <object) 
)   -- or some other location property
)   if it is <your coordinates)  then
)     -- the object exists at the desired location
)   else
)     -- it exists, but not at the desired location
)   end if
) else
)   -- it doesn't exist at all
) end if
) 
) -Bill Leue
) leue@crd.ge.com

Thanks, Bill, but I'm looking for a way to see if there's an object at a 
certain location. Rather than starting with finding a certain object and 
checking its loc, I'd like to start with a loc and see if there's an object 
there. I'm not looking for a certain object. I'm looking at a point on the
card, seeing whether or not it's an empty space.

I suppose I could put the location in a variable and check every object's
loc against it. That could be time consuming if there are a lot of obj's.
-- 

ken mohnkern#the robotics institute#carnegie mellon univ#pittsburgh pa

av@woo.oulu.fi.oulu.fi (Ari Vaulo, LuTK/TOL) (03/31/91)

From article <12497@pt.cs.cmu.edu>, by kem@h.gp.cs.cmu.edu (Kenneth Mohnkern):
> I guess HC2.0's "there is" doesn't have the ability to check if 
> there's an object at a certain point. The manual doesn't cover
> "there is" very well. I think it's only mentioned in a table of
> functions (or commands? properties?) I tried "If there is a bg 
> btn at 442,42 then beep". I got an error message.
> 
> Is there another way around this? I'd like to look at a specific 
> location and see if there's a button there without looking at
> every button and comparing its loc with the desired loc.
> 
> I know if there's a cool way to do this I'll find it here.
> 
> Thanks,
> 	ken
> 
> -- 
> 
> ken mohnkern#the robotics institute#carnegie mellon univ#pittsburgh pa

I solved that kind of problem by clicking at the point where I supposed 
that there could be a button or something else. But it requires special
code on every possible target. First I tried (with HC 2.0) the following
command:
    click at xloc,yloc
It was easy to look using TARGET function which object was at location
(xloc,yloc), but it was a bit harmful because it executes all the mouse*
command handlers and I should modify the command with shift,command, and
option keys:
    click at xloc,yloc with cmdkey

and in possible targets

  on mouseUp
     if the cmdKey is "down" then
        exit mouseUp
     else
        {code what the button should normally do}
     end if
  end mouseUp

And at last I found that the possible solution isn't elegant, but it works.
You should put the following code in your script where you want to find
other objects:
   
    ...
    global KLIKATTU,OSUMA
    put empty into OSUMA
    put "Joo" into KLIKATTU
    click at xloc,yloc
    put empty into KLIKATTU
    if OSUMA is not empty then
       {the name of the object located at xloc,yloc is in variable OSUMA}
       {and it could be anything card, button, field, and so on.
    ...

And in every object where is either some mouse* handlers or are your
possible targets you should put the following code:

   on mouseUp
      global KLIKATTU
      if KLIKATTU is empty then
         {code what the object should normally do}
      else
         global OSUMA
         put the name of me into OSUMA
         exit mouseUp 
      end if
   end mouseUp

I don't like global with object oriented like code, but sometimes it is MUST.
I'm trying to do draughts (or checkers) game with HC (I'm not sure that it
will be ever ready) and there I need this kind of scripts.

Ari





Ari Vaulo ---------------------------------------- eMail: av@tolsun.oulu.fi
University of Oulu --------------------------------------------------------
Department of Information Processing Science ------------------------------
Finland --------------------------------------------- voice: +358-81-352647

kem@h.gp.cs.cmu.edu (Kenneth Mohnkern) (04/02/91)

Thanks to everyone who sent me solutions to my request. Most didn't do
exactly what I wanted, but I appreciate the efforts. The person who came
closest to fulfilling my wishes was Ari Vaulo, who posted his solution
here.

It reads:
) my original problem:
) )  I guess HC2.0's "there is" doesn't have the ability to check if 
) )  there's an object at a certain point. The manual doesn't cover
) )  "there is" very well. I think it's only mentioned in a table of
) )  functions (or commands? properties?) I tried "If there is a bg 
) )  btn at 442,42 then beep". I got an error message.
) )  [blah, blah, blah...]
) 
) I solved that kind of problem by clicking at the point where I supposed 
) that there could be a button or something else. But it requires special
) code on every possible target. First I tried (with HC 2.0) the following
) command:
)     click at xloc,yloc
) It was easy to look using TARGET function which object was at location
) (xloc,yloc), but it was a bit harmful because it executes all the mouse*
) command handlers and I should modify the command with shift,command, and
) option keys:
)     click at xloc,yloc with cmdkey
) 
) and in possible targets
) 
)   on mouseUp
)      if the cmdKey is "down" then
)         exit mouseUp
)      else
)         {code what the button should normally do}
)      end if
)   end mouseUp
) 
) And at last I found that the possible solution isn't elegant, but it works.
) You should put the following code in your script where you want to find
) other objects:
)    
)     ...
)     global KLIKATTU,OSUMA
)     put empty into OSUMA
)     put "Joo" into KLIKATTU
)     click at xloc,yloc
)     put empty into KLIKATTU
)     if OSUMA is not empty then
)        {the name of the object located at xloc,yloc is in variable OSUMA}
)        {and it could be anything card, button, field, and so on.
)     ...
) 
) And in every object where is either some mouse* handlers or are your
) possible targets you should put the following code:
) 
)    on mouseUp
)       global KLIKATTU
)       if KLIKATTU is empty then
)          {code what the object should normally do}
)       else
)          global OSUMA
)          put the name of me into OSUMA
)          exit mouseUp 
)       end if
)    end mouseUp
) 
) I don't like global with object oriented like code, but sometimes it is MUST.
) I'm trying to do draughts (or checkers) game with HC (I'm not sure that it
) will be ever ready) and there I need this kind of scripts.
) 

This is a pretty complex solution. I thought something like just:
	(in the card script)
	on mouseUp
	  ...
	  put theDesiredLocation into dLoc
	  click at dLoc
	  if the target contains "useful button" then
	    -- I've found something good.
	  else exit mouseUp
	  -- or do something else...
	end mouseUp

I'll fool with it a little and see where this gets bad results and why
I'll need to use Ari's solution.

Again, thanks to all.

	ken
-- 

ken mohnkern#the robotics institute#carnegie mellon univ#pittsburgh pa