Is it possible to send a click (mouseUp) to a particular word in a field?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Is it possible to send a click (mouseUp) to a particular word in a field?

Post by Fermin » Sat Apr 03, 2021 9:24 pm

Is it possible to send a click (mouseUp) to a particular word in a field or, alternatively, to a particular line in that field?

For example, let's say I have a field called 'Beatles' with four lines with one word on each line:

GEORGE
RINGO
JOHN
PAUL

and in its script:

Code: Select all

on mouseup
   put value (the clickline) into theName
   
   if theName is george then answer theName && "HARRISON"
   else 
      if theName is john then answer theName && "LENNON"
      else 
         if theName is paul then answer theName && "McCARTNEY"
         else 
            if theName is ringo then answer theName && "STARR"
         end if
      end if
   end if
 
end mouseup
--
I guess the logical thing to do would be to include handlers like 'on ringo' to be triggered by 'send ringo to fld Bealtes'.

But I would like something like:

Code: Select all

send mouseup to word "Ringo" in fld "beatles".
but of course, I don't think that's possible

In summary, I would like to know if there is a way to 'direct' a mouseup to a word or a specific line.

Thank you very much.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is it possible to send a click (mouseUp) to a particular word in a field?

Post by dunbarx » Sat Apr 03, 2021 9:32 pm

Hi.

Is it that you want to be able to select the line that contains a particular word? There is no reason to click on that line, though it would be just another exercise to do so. But why not, given your Beatles are in a field 1 and a button somewhere, this in the button script

Code: Select all

on mouseUp
   select line lineOffset("Ringo",fld 1) of fld 1
end mouseUp
Or if you want the word only:

Code: Select all

on mouseUp
   select word wordoffset("Ringo",fld 1) of fld 1
end mouseUp
The reason for my question above is that you cannot send a message to a word in a field. Only objects can receive such things.

Craig

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: Is it possible to send a click (mouseUp) to a particular word in a field?

Post by Fermin » Sat Apr 03, 2021 10:18 pm

Thanks, Craig, I know that method and it is very useful to know the position of a line (or a word) in a field, for example to use something like:

Code: Select all

click at line 3 of fld "beatles"
but that doesn't work... and what I want to know is how to send, from another process, a click to the field so that the field script knows which line has been clicked on.
Or in short: Is there a way to code a click on a specific line in a field? :)

andresdt
Posts: 146
Joined: Fri Aug 16, 2019 7:51 pm

Re: Is it possible to send a click (mouseUp) to a particular word in a field?

Post by andresdt » Sat Apr 03, 2021 10:25 pm

Well the answer to your question is yes.

Code: Select all

on mouseUp
     select line 1 of fld 1
     click button 1 at the selectedLoc
end mouseUp
Now I ask you if it is not easier for you to create a custom manipulator. Let it be the one that is called when it is clicked on the field and you can call it from anywhere else by passing the line number you want to select as a parameter.
Field code

Code: Select all

on mouseUp
	selectBeatlesMember the hilitedLine of me
end mouseUp

Code on the card

Code: Select all

command selectBeatlesMember pNum
     if pNum is not an integer then exit selectBeatlesMember
     if the hilitedLine of field "Beatles" is not pNum
     then set the hilitedLine of field "Beatles" to pNum
     put the text of line pNum of field "Beatles" into tBeatles
     answer tBeatles
end selectBeatlesMember
Code on the button N

Code: Select all

on mouseUp
	// I set it to be random for any member of the Beatles to return to me. In your case you must put the number of the line.
	selectBeatlesMember random(4)
end mouseUp

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: Is it possible to send a click (mouseUp) to a particular word in a field?

Post by Fermin » Sat Apr 03, 2021 10:42 pm

Yes!!! The selectedloc is what I needed.

Code: Select all

put "Paul" into tWord
put lineoffset (tWord,fld beatles) into tLine
select line tline of control beatles
click at the selectedloc
It works perfectly.
Thank you very much...

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: Is it possible to send a click (mouseUp) to a particular word in a field?

Post by Fermin » Sat Apr 03, 2021 11:27 pm

As usual, there are many different ways to get to the same result. LiveCode has buttons with menus and other types of controllers that would probably work for me, but I tend to use fields with the titles of actions written on their lines that act as triggers or items in a classic menu. It's a bit primitive but I'm familiar with it from the distant days of Hypercard... or was it Supercard? :D
Normally I usually click 'manually' on the desired title (the line) but lately I needed to trigger it from another process and for that SelectedLoc is great.
I also think that there is a way to know the absolute position (referred to the screen) of a line of a field and that would also have been useful but, without a doubt, the selectedloc is perfect.
Thank you very much, Andresdt

Translated with www.DeepL.com/Translator (free version)

Post Reply

Return to “Talking LiveCode”