• mySQL not returning any values on query
    2 replies, posted
I am trying to make a function that checks for a players # of points, and then return that value when the function is called Heres my function: function getperkpoints(ply) local points = 0 local getpoints1 = DB_CONNECT:query("SELECT points FROM perkaddon WHERE ID = '"..ply:SteamID().."'") getpoints1.onSuccess = function(q,d) if tonumber(d[1]['points']) == nil then points = 0 else local points2 = tonumber(d[1]['points']) points = points2 end return(points2) end getpoints1:start() end And heres the code that calls the function: local points = getperkpoints(ply) print("Points: "..points) And heres my error: [ERROR] addons/perks/lua/entities/perkdistributer/init.lua:46: attempt to concatenate local 'points' (a nil value) 1. unknown - addons/perks/lua/entities/perkdistributer/init.lua:46 I am using an external mysql database not sv.db I am new to mysql so any help, tips, advice is greatly appreciated.
You never return 'points' variable from that query. You always return 'points2'. Changing that; points = points2 end return(points2) end getpoints1:start() part to: points = points2 end return(points) end getpoints1:start() might fix your problem. Not sure though..
Returning inside the onSuccess function just returns back to whatever called it, not your function. Unless you tell the query to wait it's not going to execute before the function returns. You don't want it to wait, that'd cause hangs. You'll have to pass another callback inside your getperkpoints function. A more complex solution is using coroutines.
Sorry, you need to Log In to post a reply to this thread.