Maneuver within a grid of fields
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Maneuver within a grid of fields
I have been playing with a crossword puzzle app. I have #rows x #columns sets of boxes in which to enter the letters. These are groups containing a grc (to color in blank spaces), an index (numbering the across or down beginnings) and a field for the Letter. Livecode will naturally allow the player to tab through the letter field of the boxes/grps using the TAB key, but I would like to also use the arrow keys. An "on arrowkey the key" type handler works, except I do not know how to change the focus from the former letter field to the new one found using arrow keys. I am confused about "focus" and how to enter data in a field without using the mouse or the tab key.
Re: Maneuver within a grid of fields
Hi.
Do you have your fields ordered in any grid-like way? If not, you need to. For example, you could name the fields "R1 C3" or "R4 C5" (row 1 column 3, etc,)
Then, since you have a fixed array of fields, you always know what the neighbors are named. If the cursor was in one of the examples above, say "R1C3", then you can write a card handler that traps the "arrowkey" message, along with its parameter, and select the text of the appropriate adjacent field. So if the parameter was "down" you would select the text of the field who's name had its numerical part of the first word in its name one more than the original.
Where is the trap in this method? How do you fix it? Would you have found it on your own? Sometimes it is difficult for the author to test his own work.
Look up "focus", "selectedText" and "select" in the dictionary. You can use any of these to change the cursor location in a field. I suggest you make it work with all three, just for practice. Write back if you get stuck, but only after you do get stuck.
Craig Newman
Do you have your fields ordered in any grid-like way? If not, you need to. For example, you could name the fields "R1 C3" or "R4 C5" (row 1 column 3, etc,)
Then, since you have a fixed array of fields, you always know what the neighbors are named. If the cursor was in one of the examples above, say "R1C3", then you can write a card handler that traps the "arrowkey" message, along with its parameter, and select the text of the appropriate adjacent field. So if the parameter was "down" you would select the text of the field who's name had its numerical part of the first word in its name one more than the original.
Where is the trap in this method? How do you fix it? Would you have found it on your own? Sometimes it is difficult for the author to test his own work.
Look up "focus", "selectedText" and "select" in the dictionary. You can use any of these to change the cursor location in a field. I suggest you make it work with all three, just for practice. Write back if you get stuck, but only after you do get stuck.
Craig Newman
Re: Maneuver within a grid of fields
Hi Craig,
This one caught my attention as well but I just stared at it. Of course R1 C1 etc. where was me head this morning.
Simon
This one caught my attention as well but I just stared at it. Of course R1 C1 etc. where was me head this morning.

I'd add openField and closeField as the fields are unlocked.Look up "focus", "selectedText" and "select" in the dictionary
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Maneuver within a grid of fields
Hi all.
You could try this.
As soon as you have the name of the field you would like to go, say field fName, you could do:
select text of fld fName (which text is one char in your case)
If you are editing the field, then arrowkeys work inside there only.
One way to avoid this is to use the field's script.
For a more detailed messages handling I'd use the other handlers mentioned by Craig and Simon.
You could try this.
As soon as you have the name of the field you would like to go, say field fName, you could do:
select text of fld fName (which text is one char in your case)
If you are editing the field, then arrowkeys work inside there only.
One way to avoid this is to use the field's script.
Code: Select all
on arrowkey k
myArrowkey k
end arrowkey
-- where myArrowkey is that handler in card script (or group script)
-- that determines fName and selects fld fName
shiftLock happens
Re: Maneuver within a grid of fields
Or use a behavior assigned to each editable field. This is a perfect example of a good use for behaviors.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com