Lua:在表中搜索键,如果不存在则增加索引并重试。
2014-8-20 10:24:0
收藏:0
阅读:94
评论:2
情况:
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 }-数字不固定
table.check_boxes = {[12]=一个函数,
[14]=一个函数,
[15]=一个函数,
[24]=一个函数,
[29]=一个函数,
....(n)}
正如您所看到的,x / y_coord形成check_boxes。例如:
table.x_coord[1]..table.y_coord[1]〜table.check_boxes[1]
我用这个在终端内移动光标到复选框之间。
问题现在是在我的游标动作中。 目前,我有一个函数,它根据给定的输入(箭头键)搜索下一个左/右/上/下的x / y_coord。 用return / space我调用复选框后面的函数。
现在,这可能会将光标设置在未给出复选框的位置。实际上,这并不是一个大问题,因为当input == space / return时,inputhandler调用函数
table.check_boxes[table.x_coorx[x_index]..table.y_coords[y_index]]
所以如果光标没有指向函数,就什么都不会发生。 但是现在我想强制将光标移到下一个复选框。我能做什么?
到目前为止我的想法:
根据左/右/上/下的输入以下功能:
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->好的,坐标在复选框上
x_index = x_index +1--或-1
if table.x_coord[x_index]== nil then
x_index = 1
结束
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
它太慢了。
点赞
用户3911769
function cursorTioNextBoxRight()
search_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
2014-08-20 10:22:41
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
本地变量 x_newIndex 等于 x_index + 1 --[[ 或者 -1 --]] x_index = table.x_coord[x_newIndex] and x_newIndex or x_index当 x_newIndex 在表中存在时,x_index 的值会变为 x_newIndex,否则会保持原来的 x_index 值。