Page 1 of 1
Pass the name of me?
Posted: Thu Nov 22, 2012 6:43 am
by planix
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
Re: Pass the name of me?
Posted: Thu Nov 22, 2012 7:01 am
by planix
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.

Is there a more elegant way to pass this reference?
cheers
Re: Pass the name of me?
Posted: Thu Nov 22, 2012 8:11 am
by shaosean
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 &
Re: Pass the name of me?
Posted: Thu Nov 22, 2012 10:55 am
by planix
Brilliant.
Worked like a charm.
I didn't realise you could pass variables like that.
Much more elegant.
Re: Pass the name of me?
Posted: Thu Nov 22, 2012 12:03 pm
by Mark
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
Re: Pass the name of me?
Posted: Fri Nov 23, 2012 12:20 am
by planix
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
Re: Pass the name of me?
Posted: Fri Nov 23, 2012 12:26 am
by Mark
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
Re: Pass the name of me?
Posted: Fri Nov 23, 2012 3:27 am
by planix
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
Re: Pass the name of me?
Posted: Fri Nov 23, 2012 11:19 am
by Mark
No, I mean why don't you call the command directly?
Kind regards,
Mark
Re: Pass the name of me?
Posted: Fri Nov 23, 2012 7:07 pm
by jacque
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.
Re: Pass the name of me?
Posted: Sat Nov 24, 2012 12:27 am
by planix
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
Re: Pass the name of me?
Posted: Sat Nov 24, 2012 12:38 am
by sturgis
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
Re: Pass the name of me?
Posted: Sat Nov 24, 2012 12:44 am
by Mark
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
which will call the checkPosition handler directly.
It is just one of many ways you can do things in LiveCode.
Kind regards,
Mark