sorry if i am bothering you now, i am still learning. but i need help. could you correct me and script how to check and then get value of array 2d for checking further and counting points ?
example array2d syntax that i build :
role = {{[name],[points],[indexpoint]},
{[...],[...],[...]}}
example array2d value that i make :
role = {{"mike", 30, "1"},
{"michael", 40, "2"},
{"mike", 40, "2"},
{"michael", 50, "3"},
{"frost", 50, "3"},
{"nick", 60, "4"}}
what i wanted is. when i am searching for name "michael". it will detect value in the array. something like this
local player_data = {{"michael", 40, "2"},{"michael", 50, "3"}}
so after this, i can count the points that he already have. 40+50
and the result "90" will send to new variable like resultpoint = 90
so the print will show like this
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"
my long code here :
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
is this really possible ? if there is a simple way or more less code, let me know. i know, it's too much code. i am still newbie