Page 1 of 1

How to check "if the target is a button" ?

Posted: Sat Jun 01, 2019 8:00 pm
by sritcp
Is there a way to check the type of object that was clicked on?

I see that "is" and "is among" works only with number, words, etc.

Regards,
Sri

Re: How to check "if the target is a button" ?

Posted: Sat Jun 01, 2019 8:36 pm
by [-hh]
For example:

Code: Select all

the target begins with "button "

Re: How to check "if the target is a button" ?

Posted: Sat Jun 01, 2019 8:40 pm
by sritcp
Of course, Hermann!

I'd used "the short name of the target" in my script, so "button" was not available to me! (forehead-slap)

Thanks!

Sri

Re: How to check "if the target is a button" ?

Posted: Sat Jun 01, 2019 9:38 pm
by bogs
And of course there are lots of variations, like

Code: Select all

word 1 of the target
last target 
etc.

Re: How to check "if the target is a button" ?

Posted: Sun Jun 02, 2019 2:01 pm
by dunbarx
Academic at this point, but just to close your original idea:

Code: Select all

answer word 1 of the long name of the target
Craig

Re: How to check "if the target is a button" ?

Posted: Sun Jun 02, 2019 2:16 pm
by richmond62
obType.png
obType.png (29.25 KiB) Viewed 563 times
-
stuck this in the cardScript:

Code: Select all

on mouseUp
   put word 1 of the target
end mouseUp

Re: How to check "if the target is a button" ?

Posted: Mon Jun 03, 2019 6:43 pm
by FourthWorld
Anyone know offhand whether both "the target" and "the name of the object" are affected by background buttons or card fields when the stack's hcAddressing property is set to true?

Sure, it's an edge case, and since that property was really only useful for HC ports it probably hasn't mattered in more than a decade. But for the sake of thoroughness it may be good to know.

Re: How to check "if the target is a button" ?

Posted: Mon Jun 03, 2019 7:51 pm
by dunbarx
Never played with this before but a couple of things:

1- Cmd-D will not duplicate an object if the hcAdressing is "true"
2- Not a surprise, but one cannot group objects if "true". I did not know that hcAdressing limited a stack in the same way a HC stack would be. There must be many other similar restrictions...

3- As to the target and the name of, say, a backGround button, (that is, a button which is a child of a bg group) if hcAdressing is false:

Code: Select all

button "Button"
button "Button"
if true:

Code: Select all

bkgnd button "Button"
bkgnd button "Button"
Craig

Re: How to check "if the target is a button" ?

Posted: Mon Jun 03, 2019 8:14 pm
by FourthWorld
Thanks, Craig.

So if we were to write a function taking hcAddressing into account, it might be something like this (off the cuff, test before using):

Code: Select all

function ObjectType pObj
  -- Check if valid object reference:
  if there is not a pObj then return empty
  -- Get stack name:
  put the long id of pObj into tStack
  put offset(" of stack ", pObj) into tOffset
  delete char 1 to (tOffset+3) of tStack
  -- Return value according to hcAddressing:
  if the hcAddressing of stack tStack is true then
      return word 2 of the name of  pObj
  else
     return word 1 of the name of pObj
  end if
end ObjectType