状況:
table = { this, that, something else, x_coord, y_coord }
table.x_coord = { 1,2,3,4,7,8,n}
table.y_coord = { 2,4,5,9,n} -- numbers aren't fix
table.check_boxes = { [12] = a function,
[14] = a function,
[15] = a function,
[24] = a function,
[29] = a function,
....(n) }
ご覧のとおり、check_boxes を形成する x/y_coords です。例えば:
table.x_coord[1]..table.y_coord[1] ~ table.check_boxes[1]
これを使用して、ターミナルでカーソルを check_boxes の間に移動します。
問題は現在、カーソルの動きにあります。現在、指定された入力 (矢印キー) に応じて、次の x/y_coord を左/右/上/下に検索する関数を取得しました。リターン/スペースを使用して、チェックボックスの背後にある関数を呼び出します。
これで、check_boxes が指定されていない位置に Cursor を設定できます。入力==スペース/リターンの場合、入力ハンドラは関数を呼び出すため、実際には大したことではありません
table.check_boxes[table.x_coorx[x_index]..table.y_coords[y_index]]
したがって、カーソルが関数を指していない場合は、何も起こりません。しかし、今はカーソルを次の check_box に移動させたいと思っています。私に何ができる?
これまでの私の考え:
次の関数は、入力の左/右/上/下に応じて、x または y のいずれかになります。
while true do
for k, v in pairs(table.check_boxes) do
if(table.x_coord[x_index] .. table.y_coord[y_index] == k then break end
end -- break -> okay, coord is at a checkbox
x_index = x_index + 1 -- or -1
if table.x_coord[x_index] == nil then
x_index = 1
end
end
問題は、最後の if が x_coord = {1,3} のようなケースを許可しないことです。これは、2 に達すると x_index が 1 に設定されるためです。
任意のヒント?
編集:今、私はそれを始めました:
function cursorTioNextBoxRight()
searc_index = x_index
search = true
while search do
search_index = search_index + 1
if search_index > #table.x_coord then
search_index = 1
end
for k, v in pairs(table.check_boxes) do
if tonumber(table.x_coord[search_index..table.y_coord[y_index] == k then
x_index = search_index -- YAAAY
search = false
break
end
end
end
めちゃくちゃ遅い。