Maneuver within a grid of fields

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Kieutrang
Posts: 2
Joined: Sat Aug 31, 2019 5:05 am

Maneuver within a grid of fields

Post by Kieutrang » Sat Aug 31, 2019 5:07 am

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.

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

Re: Maneuver within a grid of fields

Post by dunbarx » Sat Aug 31, 2019 1:26 pm

Hi.

Do you have an "arrowKey" handler in, say, the card script? Are your individual fields named in such a way as to allow a natural progression through them? For example, "f1,f2,f3,..."

There are many ways to do what you want. Sometimes a bit of prep as per the above makes that medicine go down much easier.

Craig

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

Re: Maneuver within a grid of fields

Post by dunbarx » Sat Aug 31, 2019 4:21 pm

So if you have three fields named "f1", "f2". and "f3", and the cursor is in fld "f1", and this is in the card script:

Code: Select all

on arrowkey tKey
   put  the last char of the short name of the focusedObject into currentField
   if tKey = "right" then select  text of fld  ("f" & currentField + 1)
end arrowkey
Focus, and the cursor, will appear in fld "f2".

What happens when the last field is in focus?

Right. You have to manage this. Do you know how?

Craig

Post Reply

Return to “Talking LiveCode”