Finding owner of a button

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Finding owner of a button

Post by kaveh1000 » Sat Nov 17, 2018 10:46 pm

I have two buttons in a group. My script in one of the buttons says:

Code: Select all

on mouseup
   if the owner of the target is group "mine" then answer "yes"
end mouseup
But I get the following error when I click:

Code: Select all

button "Button": execution error at line 2 (Chunk: source is not a container), char 1
Any ideas pls?
Kaveh

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Finding owner of a button

Post by SparkOut » Sat Nov 17, 2018 11:15 pm

If you "put the owner of the target" you will see that it returns the string literal:

group "mine"

When it comes to your comparison, the string literal needs to be quoted. So you would need to check thus:

Code: Select all

if the owner of the target is "group" && quote & "mine" & quote then answer "yes"
You could make this neater by putting "the owner" into a variable and parsing with maybe "contains" or some such, but your problem is the comparison against the "owner of the target" that returns a string literal which contains quotes, so you need to work around that in some way.

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Finding owner of a button

Post by kaveh1000 » Sun Nov 18, 2018 12:38 am

Thank you so much @SparkOut. That gave me the hint, so the following now works:

Code: Select all

on mouseup
   put the owner of the target into the_owner
   delete char 1 to offset(quote, the_owner) of the_owner
   delete char -1 of the_owner
   if the short name of the owner of the target is the_owner then
         answer "yes"
   end if
end mouseup
I tried using replacetext() but I can't escape the quote mark!
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Finding owner of a button

Post by bogs » Sun Nov 18, 2018 2:14 pm

Escaping the quote marks is this part of the code from above -

Code: Select all

 quote & "mine" & quote 
As far as I could see, it should work out flawlessly?
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Finding owner of a button

Post by jmburnod » Sun Nov 18, 2018 3:03 pm

Hi All,
why not use the short name of the owner ?

Code: Select all

   if  the short name of the owner of the target = "mine" then answer "yes" 
works for me
Is there something i dont understand ?
Best regards
Jean-Marc
https://alternatic.ch

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Finding owner of a button

Post by kaveh1000 » Sun Nov 18, 2018 3:10 pm

Thanks Jean-Marc. So obvious in hindsight! Thank you. I am not as clever as I thought. ;-)
Kaveh

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Finding owner of a button

Post by jmburnod » Sun Nov 18, 2018 4:33 pm

I am not as clever as I thought
Welcome to the club :D
https://alternatic.ch

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”