i really need help. i am still can't figure out my logic lua code about How can i block the event with an if condition, when it already has a value?
this is my array2d :
mydata = {
{"mike", "30", "1"},
{"michael", "40", "2"},
{"mike", "40", "2"},
{"michael", "50", "3"},
{"frost", "50", "3"},
{"nick", "60", "4"}
}
actually, my plan is to get the correct code to check the index name mydata[..][1] and point index mydata[..][3].
This is an example case explanation :
so if the index name Michael and point index 3 are not exist or if only name michael exist but it doesn't have point index 3, then it will write michael:50:3 in the data.txt. but if name and point index already exist. Then, it will block and print("sorry your name and score index already exist")
My Code :
mydata = {{"mike", "30", "1"},
{"michael", "40", "2"},
{"mike", "40", "2"},
{"michael", "50", "3"},
{"frost", "50", "3"},
{"nick", "60", "4"}}
function check_point1(tab, val1) -- Function for checking name
for index, value in ipairs (tab) do
if value[1] == val1 then
return true
end
end
return false
end
function check_point2(tab, val1) -- Function for checking player point after name
for index, value in ipairs (tab) do
if value[3] == val1 then
return true
end
end
return false
end
-- this is example case
-- these below are variable to process checking if it's exist
name = "michael"
id = "3"
-- this is my checking code, idk it's good or not. or maybe it's wrong code. because it's not working
if check_point1(mydata, name) then
if check_point2(mydata, id) then
print(your name and point index are exist. sorry you can't earn this point")
else
print(only your name exist. let us save your new point now")
end
else
print("your name and point index is not exist. let us save your name and point now")
local file = io.open("data.txt", "r")
file:write("michael:50:3")
file:close()
end
What would be the best way for blocking an event "write michael:50:3" when it's already exists ? let me know if there some thing you need to understand before you help me out. i am still poor at lua.