Pass the name of me?

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
planix
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 47
Joined: Tue Mar 10, 2009 12:47 pm

Pass the name of me?

Post by planix » Thu Nov 22, 2012 6:43 am

Hi,

in the mouseUp handler of a locked text field I have a call to a card script which reads (in part)

Code: Select all

send "checkPosition " & the  name of group theGroup & "," & the name of me to this card 
the checkPosition handler is in the card and reads (in part)

Code: Select all

on checkPosition whichGroup whichObject
   --adjust the field object so that it stays within the bounds of the group
   if the left of  whichObject < the left of  whichGroup then
      set the left of  whichObject to the left of whichGroup + 10
   end if   
end checkPosition
I have found that whichGroup is 'group "gpBox1"'. But, whichObject is the text of the locked text field.

Obviously this means the card script gets a bit upset. So, I am wondering... how do I pass the name of me (the calling locked field) as 'field "textfordrag"' (or whatever) off to the checkPosition handler?

I have tried name, id, long id, etc and they all resolve to the text of the locked field.

cheers
****************************************
PLANIX
"Knowing anything is better than knowing nothing. But knowing that nothing ain't anything, why that's just plain nirvana."

planix
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 47
Joined: Tue Mar 10, 2009 12:47 pm

Re: Pass the name of me?

Post by planix » Thu Nov 22, 2012 7:01 am

Ok,

I figured out a way. Isn't that always the way? I have to say I don't like it. So, if someone has a more elegant way I would really love to see it.

The problem seems to be that when I pass 'field "thefieldname"' as a parameter it is resolved into the text of that field.

If I change my send statement to read thus

Code: Select all

send "checkPosition " & the  name of group theGroup & "," &  "the name of " & the name of me to this card
the parameter is resolved as the name of the card.

In short, I pass the instruction (?) to get the name of the object ("the name of -- the name of me") as the parameter.

Don't like it. Not happy. :cry: Is there a more elegant way to pass this reference?

cheers
****************************************
PLANIX
"Knowing anything is better than knowing nothing. But knowing that nothing ain't anything, why that's just plain nirvana."

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Pass the name of me?

Post by shaosean » Thu Nov 22, 2012 8:11 am

I usually use variables to make it easier to read and to pass

Code: Select all

local tGroupName
put the name of group theGroup into tGroupName

local tMyName
put the name of me into tMyName

send "checkPosition tGroupName, tMyName" to this card

Just another small tip, but you can replace & "," & with & COMMA &

planix
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 47
Joined: Tue Mar 10, 2009 12:47 pm

Re: Pass the name of me?

Post by planix » Thu Nov 22, 2012 10:55 am

Brilliant.

Worked like a charm.

I didn't realise you could pass variables like that.

Much more elegant.
****************************************
PLANIX
"Knowing anything is better than knowing nothing. But knowing that nothing ain't anything, why that's just plain nirvana."

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Pass the name of me?

Post by Mark » Thu Nov 22, 2012 12:03 pm

Hi,

You could also use the target:

Code: Select all

on checkPosition whichGroup
  put the name of the target into whichObject
   --adjust the field object so that it stays within the bounds of the group
   if the left of whichObject < the left of whichGroup then
      set the left of  whichObject to the left of whichGroup + 10
   end if   
end checkPosition
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

planix
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 47
Joined: Tue Mar 10, 2009 12:47 pm

Re: Pass the name of me?

Post by planix » Fri Nov 23, 2012 12:20 am

Hi Mark,

Thanks for that.

When I use the target it returns the card ID. I guess this is because the script is executing in the card?

cheers
****************************************
PLANIX
"Knowing anything is better than knowing nothing. But knowing that nothing ain't anything, why that's just plain nirvana."

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Pass the name of me?

Post by Mark » Fri Nov 23, 2012 12:26 am

Hi,

Of course, it returns the card name because you use the send command. Why are you using the send command?

Btw I'm not suggesting that my "solution" is better; Shaosean's method works perfectly.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

planix
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 47
Joined: Tue Mar 10, 2009 12:47 pm

Re: Pass the name of me?

Post by planix » Fri Nov 23, 2012 3:27 am

Thanks Mark,

I am using the "send" command primarily because I haven't experimented with "dispatch" which is the only other way that I know.

The nice thing about livecode way seems to be that there are many ways to achieve the same outcome. And, it's not too hard to figure out how they work.

Thanks for the alternative way.

cheers
****************************************
PLANIX
"Knowing anything is better than knowing nothing. But knowing that nothing ain't anything, why that's just plain nirvana."

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Pass the name of me?

Post by Mark » Fri Nov 23, 2012 11:19 am

No, I mean why don't you call the command directly?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Pass the name of me?

Post by jacque » Fri Nov 23, 2012 7:07 pm

If it's a background group, the card won't receive the message. If it's a card group, then I'd call it directly as you say.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

planix
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 47
Joined: Tue Mar 10, 2009 12:47 pm

Re: Pass the name of me?

Post by planix » Sat Nov 24, 2012 12:27 am

Hi,

It is a card group. I am calling from the mouseUp related to the dragged field. The code for processing the call is in the card. The group name/ID is pulled from the list of groups on the card.

I'm not sure how I would call the card routine directly from the mouseUp in the dragged field without using send or dispatch.

Is it just a matter of putting the command + paramters without a send?

cheers
****************************************
PLANIX
"Knowing anything is better than knowing nothing. But knowing that nothing ain't anything, why that's just plain nirvana."

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Pass the name of me?

Post by sturgis » Sat Nov 24, 2012 12:38 am

Yes. If you have a command in the card:

Code: Select all

command testCommand pVar1, pVar2
   put merge("Var 1: [[pVar1]]  Var 2: [[pVar2]]")
end testCommand


your button can call it like so

Code: Select all

on mouseUp
   testCommand "whateverforvariable1","whateverforvariable2" 
end mouseUp
which will put the results into the msg box:
Var 1: whateverforvariable1 Var 2: whaeverforvariable2
planix wrote:
Is it just a matter of putting the command + paramters without a send?

cheers

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Pass the name of me?

Post by Mark » Sat Nov 24, 2012 12:44 am

Hello,

If your field isn't in a group or if it is in a group but the backgroundBehavior of that group is false (which it is by default), I think you could replace the line in Shaosean's script

Code: Select all

send "checkPosition tGroupName, tMyName" to this card
with

Code: Select all

checkPosition tGroupName, tMyName
which will call the checkPosition handler directly.

It is just one of many ways you can do things in LiveCode.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply