hello facepunch users,
I currently have this code:
[code]
function SetupTobiasTime(ply)
local query1 = db3:query("SELECT * FROM `tobiasx_time` WHERE `id` = '"..ply:SteamID().."';")
query1.onSuccess = function(q)
if !checkQuery(q) then
local query2 = db3:query("INSERT INTO `tobiasx_time` (id, time) VALUES ('"..ply:SteamID().."', '0')")
query2:start()
ply:SetTime(0)
ply:SetStartTime(CurTime())
else
query1.onData = function(q, d)
ply:SetTime(d.time)
ply:SetStartTime(CurTime())
end
end
end
query1.onError = function(Q,E) ServerLog("Failed to load player time. Error: ") print(E) end
query1:start()
end
hook.Add("PlayerInitialSpawn", "SetupTobiasTime", SetupTobiasTime)[/code]
which is suppose to grab the time of a player, and apply it to them, but currently it doesn't work correctly.
if the player does not exist in the database, it creates it, and sets their time to 0, but if they are already created, it doesn't grab their current time, and set it.
I tried a print statement for d.time, and it didnt come up.
What am I doing wrong when retrieving the time from the database? I'd really appreciate it if someone explained it to me.
Thanks.
Some more info would be nice. Which conditionals does the code make it to/through?
[QUOTE=RealDope;49574073]Some more info would be nice. Which conditionals does the code make it to/through?[/QUOTE]
The database has 2 columns, "id" and "time"
What I'm currently trying to do is grab the int from time, and then set it on the player through a custom function of mine.
(sorry if I didn't answer what you asked.)
[QUOTE=Tobiasx;49574116]The database has 2 columns, "id" and "time"
What I'm currently trying to do is grab the int from time, and then set it on the player through a custom function of mine.
(sorry if I didn't answer what you asked.)[/QUOTE]
You've got a bunch of if statements in your code. Add print messages to each and show the output so we can see where the code stops.
[QUOTE=RealDope;49574149]You've got a bunch of if statements in your code. Add print messages to each and show the output so we can see where the code stops.[/QUOTE]
the code stops at query1.onData according to my print statements.
the print statement from there doesn't even print.
OnSuccess returns the data as second arg, just use that.
You're defining the OnData function after the query has executed and attempted to call that function.
Sorry, you need to Log In to post a reply to this thread.