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

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!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

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

Post 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
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post by [-hh] »

For example:

Code: Select all

the target begins with "button "
shiftLock happens
sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

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

Post 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
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs »

And of course there are lots of variations, like

Code: Select all

word 1 of the target
last target 
etc.
Image
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10509
Joined: Wed May 06, 2009 2:28 pm

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

Post 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
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10430
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 »

obType.png
obType.png (29.25 KiB) Viewed 8512 times
-
stuck this in the cardScript:

Code: Select all

on mouseUp
   put word 1 of the target
end mouseUp
Attachments
object type.livecode.zip
Here's the stack
(974 Bytes) Downloaded 524 times
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10105
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10509
Joined: Wed May 06, 2009 2:28 pm

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

Post 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
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10105
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post 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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Post Reply