Yurigarga Posted July 24, 2018 Share Posted July 24, 2018 [2018-07-24 15:27:27] ERROR: [gameplay]/--Freeroam/fr_server.lua:586: attempt to perform arithmetic on a nil value Help me Please solve problem? -- LEVEL -- Top3 = {} function getPlayersSortByaData() local Top = {} local CreatTop = executeSQLQuery( "SELECT * FROM SHLevel ORDER BY level DESC LIMIT 30" ) for i = 1, #CreatTop do table.insert (Top, { Account = getAccountData(getAccount(CreatTop[i].hesap_adi),"nickname") or CreatTop[i].nickname , aScore = CreatTop[i].level or 1 , aTecrube = tonumber(CreatTop[i].level)+(tonumber(getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' ))/100000) or 0 , ---583 } ) end table.remove(Top3) Top3 = {} if #CreatTop >0 then table.sort(Top, function(a,b) return (tonumber(a.aTecrube)or 0) > (tonumber(b.aTecrube)or 0) end) for k, data in ipairs(Top) do table.insert(Top3,{name = data.Account,score = data.aScore, sira = k}) if k == 30 then table.remove(Top) break end end end end getPlayersSortByaData() addEvent("getTop2", true) addEventHandler("getTop2", root,function() triggerClientEvent(source, "SetData", source, Top3) end) Link to comment
Addlibs Posted July 24, 2018 Share Posted July 24, 2018 aTecrube = (tonumber(CreatTop[i].level) or 0) + (tonumber(getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' )) or 0)/100000), Make sure to add 'or' fallbacks when using tonumber: tonumber("invalid number") returns a nil, not a 0. To get a 0 if an invalid number is entered, use (tonumber("invalid number") or 0) 1 Link to comment
Yurigarga Posted July 24, 2018 Author Share Posted July 24, 2018 15 minutes ago, MrTasty said: aTecrube = (tonumber(CreatTop[i].level) or 0) + (tonumber(getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' )) or 0)/100000), Make sure to add 'or' fallbacks when using tonumber: tonumber("invalid number") returns a nil, not a 0. To get a 0 if an invalid number is entered, use (tonumber("invalid number") or 0) I do not understand what you mean. Please add to the string Link to comment
Addlibs Posted July 24, 2018 Share Posted July 24, 2018 local level = tonumber ( CreatTop[i].level ) or 0 -- attempt to convert to number or return a 0 local experience = tonumber ( getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' ) ) or 0 -- attempt to convert to a number or return a 0 table.insert (Top, { Account = getAccountData ( getAccount ( CreatTop[i].hesap_adi ), "nickname" ) or CreatTop[i].nickname , aScore = CreatTop[i].level or 1 , aTecrube = level + ( experience / 100000 ) -- add them together } ) I've accidentally added one closing bracket too many in my previous post. Anyway, making use of variables makes this a lot clearer. 1 Link to comment
Yurigarga Posted July 24, 2018 Author Share Posted July 24, 2018 4 minutes ago, MrTasty said: local level = tonumber ( CreatTop[i].level ) or 0 -- attempt to convert to number or return a 0 local experience = tonumber ( getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' ) ) or 0 -- attempt to convert to a number or return a 0 table.insert (Top, { Account = getAccountData ( getAccount ( CreatTop[i].hesap_adi ), "nickname" ) or CreatTop[i].nickname , aScore = CreatTop[i].level or 1 , aTecrube = level + ( experience / 100000 ) -- add them together } ) I've accidentally added one closing bracket too many in my previous post. Anyway, making use of variables makes this a lot clearer. Thanks bro .... I compared it now [2018-07-24 23:21:22] ERROR: [gameplay]/SH-Freeroam/fr_server.lua:592: attempt to get length of global 'CreatTop' (a nil value) ------ Player ranking ------- -- LEVEL -- Top3 = {} function getPlayersSortByaData() local Top = {} local level = tonumber ( CreatTop[i].level ) or 0 -- attempt to convert to number or return a 0 local experience = tonumber ( getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' ) ) or 0 -- attempt to convert to a number or return a 0 table.insert (Top, { Account = getAccountData ( getAccount ( CreatTop[i].hesap_adi ), "nickname" ) or CreatTop[i].nickname , aScore = CreatTop[i].level or 1 , aTecrube = level + ( experience / 100000 ) -- add them together } ) end table.remove(Top3) Top3 = {} if #CreatTop >0 then table.sort(Top, function(a,b) return (tonumber(a.aTecrube)or 0) > (tonumber(b.aTecrube)or 0) end) for k, data in ipairs(Top) do table.insert(Top3,{name = data.Account,score = data.aScore, sira = k}) if k == 30 then table.remove(Top) break end end end getPlayersSortByaData() addEvent("getTop2", true) addEventHandler("getTop2", root,function() triggerClientEvent(source, "SetData", source, Top3) end) Link to comment
Addlibs Posted July 24, 2018 Share Posted July 24, 2018 Seems like you deleted local CreatTop = executeSQLQuery( "SELECT * FROM SHLevel ORDER BY level DESC LIMIT 30" ) which existed between lines 8 and 9, which means CreatTop is nil (not defined). Try adding that line back in. 1 Link to comment
Yurigarga Posted July 25, 2018 Author Share Posted July 25, 2018 (edited) -- LEVEL -- Top3 = {} function getPlayersSortByaData() local CreatTop = executeSQLQuery( "SELECT * FROM SHLevel ORDER BY level DESC LIMIT 30" ) local Top = {} local level = tonumber ( CreatTop[i].level ) or 0 -- attempt to convert to number or return a 0 local experience = tonumber ( getAccountData ( getAccount(CreatTop[i].hesap_adi), 'experience' ) ) or 0 -- attempt to convert to a number or return a 0 table.insert (Top, { Account = getAccountData ( getAccount ( CreatTop[i].hesap_adi ), "nickname" ) or CreatTop[i].nickname , aScore = CreatTop[i].level or 1 , aTecrube = level + ( experience / 100000 ) -- add them together } ) end table.remove(Top3) Top3 = {} if #CreatTop >0 then table.sort(Top, function(a,b) return (tonumber(a.aTecrube)or 0) > (tonumber(b.aTecrube)or 0) end) for k, data in ipairs(Top) do table.insert(Top3,{name = data.Account,score = data.aScore, sira = k}) if k == 30 then table.remove(Top) break end end end getPlayersSortByaData() addEvent("getTop2", true) addEventHandler("getTop2", root,function() triggerClientEvent(source, "SetData", source, Top3) end) [2018-07-25 09:58:28] ERROR: [gameplay]/SH-Freeroam/fr_server.lua:595: attempt to get length of global 'CreatTop' (a nil value) if #CreatTop >0 then He says the same thing again Edited July 25, 2018 by Yurigarga Link to comment
Discord Moderators Pirulax Posted July 25, 2018 Discord Moderators Share Posted July 25, 2018 (edited) So, line 595 is "if #CreatTop>0 then"? Also, set you tab key to insert spaces instead of tabs, because(bc) this linter doesn't love tabs that much, and it brokes the indentation. Edited July 25, 2018 by Pirulax Link to comment
Yurigarga Posted July 25, 2018 Author Share Posted July 25, 2018 23 hours ago, MrTasty said: Seems like you deleted local CreatTop = executeSQLQuery( "SELECT * FROM SHLevel ORDER BY level DESC LIMIT 30" ) which existed between lines 8 and 9, which means CreatTop is nil (not defined). Try adding that line back in. 2018-07-25 09:58:28] ERROR: [gameplay]/SH-Freeroam/fr_server.lua:595: attempt to get length of global 'CreatTop' (a nil value) HELPPPPPPP Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now