在多个Lua列表中搜索一个项目
我现在正在编写一个脚本,遇到了一个障碍,我不太清楚如何检查某个值是否在 Lua 中的任何选定表中。
下面问题的示例脚本。
players = {213, 644}
helpers = {632, 965}
-- How would I check if a number (for example 632) was in either of these two tables?
I'm working on a script right now and have encountered a roadblock where I can't quite figure out how to check if a value is in any of the selected tables in Lua.
Example script of the problem below.
players = {213, 644}
helpers = {632, 965}
-- How would I check if a number (for example 632) was in either of these two tables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用这个简单的表查找值
_v
:Use this simple table find value
_v
:要检查某个值是否在列表中,您需要遍历该列表并将每个元素与您要查找的值进行比较。
如果您想对多个列表执行此操作,则需要对每个列表执行此操作。
To check wether a value is in a list you need to traverse over that list and compare each element with the value you're looking for.
If you want to do this for multiple lists you need to do this for each of the lists.
如果表是静态的或不经常更改,请尝试以下操作:
如果您需要知道在哪里找到某个项目,请执行以下操作:
If the tables are static or do not change frequently, try this:
If you need to know where an item was found, do this: