对不起,如果我现在打扰你,我还在学习。但我需要帮助。你能纠正我并编写脚本如何检查然后获取数组 2d 的值以进一步检查和计数点吗?
我构建的示例 array2d 语法:
role = {{[name],[points],[indexpoint]},
{[...],[...],[...]}}
我制作的示例 array2d 值:
role = {{"mike", 30, "1"},
{"michael", 40, "2"},
{"mike", 40, "2"},
{"michael", 50, "3"},
{"frost", 50, "3"},
{"nick", 60, "4"}}
我想要的是。当我搜索名称“michael”时。它将检测数组中的值。像这样的东西
local player_data = {{"michael", 40, "2"},{"michael", 50, "3"}}
所以在这之后,我可以计算他已经拥有的积分。40+50 和结果“90”将发送到新变量,如resultpoint = 90
所以打印会这样显示
Player "Michael"
Your points is "90"
Here is the list of your index that you earned :
1. earn 40 points in index point "2"
2. earn 50 points in index point "3"
我的长代码在这里:
role = {{"mike", "30", "1"},
{"michael", "40", "2"},
{"mike", "40", "2"},
{"michael", "50", "3"},
{"frost", "50", "3"},
{"nick", "60", "4"}}
function check_role1(tab, val)
for index, value in ipairs (tab) do
-- We grab the first index of our sub-table instead for player name
if value[1] == val then
return true
end
end
return false
end
function check_role2(tab, val)
for index, value in ipairs (tab) do
-- We grab the third index of our sub-table instead for index point
if value[3] == val then
return true
end
end
return false
end
function detectroles(name)
pn = name
if check_role1 (role, pn) then
print ('Yep')
--[[for i = 1, #role do
player_checkname[i] = role[i][1] -- Get Player Name From Array for checking further
player_checkpnt[i] = role[i][2] -- Get Player Point From Array for checking further
player_checkidpnt[i] = role[i][3] -- Get Player Point From Array for checking further]]
-- is this correct code to get value ?
end
else
print ('You dont earn any points')
end
end
detectroles("jack") -- this is call function, for checking name jack if he is in array or not
这真的可能吗?如果有简单的方法或更少的代码,请告诉我。我知道,代码太多了。我还是新手