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: FourthWorld, heatherlaine, Klaus, kevinmiller

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

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

Post by sritcp » Sat Jun 01, 2019 8:00 pm

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
Location: Göttingen, DE

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

Post by [-hh] » Sat Jun 01, 2019 8:36 pm

For example:

Code: Select all

the target begins with "button "
shiftLock happens

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

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

Post by sritcp » Sat Jun 01, 2019 8:40 pm

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: 5435
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Sat Jun 01, 2019 9:38 pm

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: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » Sun Jun 02, 2019 2:01 pm

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: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Sun Jun 02, 2019 2:16 pm

obType.png
obType.png (29.25 KiB) Viewed 4361 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 168 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Mon Jun 03, 2019 6:43 pm

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: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » Mon Jun 03, 2019 7:51 pm

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: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Mon Jun 03, 2019 8:14 pm

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

Return to “Getting Started with LiveCode - Complete Beginners”