Yurigarga Posted July 26, 2018 Share Posted July 26, 2018 -- 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) 595 line ======== if #CreatTop >0 then Please Help me what should I do. Please solve problem? Link to comment
JeViCo Posted July 26, 2018 Share Posted July 26, 2018 local CreatTop = executeSQLQuery( "SELECT * FROM SHLevel ORDER BY level DESC LIMIT 30" ) it has a nil value. I guess a table with name 'SHLevel' doesn't exists in registry.db. So - create it! 1 Link to comment
Discord Moderators Pirulax Posted July 26, 2018 Discord Moderators Share Posted July 26, 2018 3 hours ago, Juuve said: local CreatTop = executeSQLQuery( "SELECT * FROM SHLevel ORDER BY level DESC LIMIT 30" ) it has a nil value. I guess a table with name 'SHLevel' doesn't exists in registry.db. So - create it! No, it's not. Because if CreatTop is a nil value it should thrown an error at line 8. Link to comment
JeViCo Posted July 26, 2018 Share Posted July 26, 2018 1 hour ago, Pirulax said: No, it's not. Because if CreatTop is a nil value it should thrown an error at line 8. nope. It returns 0. You forgot about OR 0. Same condition at line 9, 12, 13 Link to comment
Discord Moderators Pirulax Posted July 26, 2018 Discord Moderators Share Posted July 26, 2018 (edited) local level = tonumber ( CreatTop[i].level ) or 0 -- attempt to convert to number or return a 0 First CreatTop.level is evaluated and then if tonumber() returns a false CONDITION then or's other side(0 here) is returned. It's called a ternary operation. Edited July 26, 2018 by Pirulax 1 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