hey i am making something, but the db is not creating; this is what i have so far
[code]
function DB.Init()
sql.Begin()
sql.Query("CREATE TABLE IF NOT EXISTS game_wallets('steam' TEXT NOT NULL, 'amount' INTEGER NOT NULL, PRIMARY KEY('steam'));")
sql.Commit()
end
function DB.StoreCredit(ply, amount)
if not ValidEntity(ply) then return end
if amount < 0 then return end
local steamID = ply:SteamID()
local r = sql.QueryValue("SELECT amount FROM game_wallets WHERE steam = " .. sql.SQLStr(steamID) .. ";")
if r then
sql.Query("UPDATE game_wallets SET amount = " .. math.floor(amount) .. " WHERE steam = " .. sql.SQLStr(steamID) .. ";")
else
sql.Query("INSERT INTO game_wallets VALUES(" .. sql.SQLStr(steamID) .. ", " .. math.floor(amount) .. ");")
end
ply:SetNWInt("credit", math.floor(amount))
end
function DB.RetrieveCredit(ply)
if not ValidEntity(ply) then return 0 end
local steamID = ply:SteamID()
local startingAmount = 1
local r = sql.QueryValue("SELECT amount FROM game_wallets WHERE steam = " .. sql.SQLStr(ply:SteamID()) .. ";")
if r then
ply:SetNWInt("credit", math.floor(r))
return r
else
-- No record yet, setting starting Credit to 1
DB.StoreCredit(ply, startingAmount)
return startingAmount
end
end
[/code]
hope someone can help ;)
Are you calling the DB.Init function? If you do, is there an error? Try using sql.LastError if you're not sure what's going on.
[QUOTE=Entoros;17453079]Are you calling the DB.Init function? If you do, is there an error? Try using sql.LastError if you're not sure what's going on.[/QUOTE]
sorry i am not shure what you meen i have no errors and i have looked in the db and game_credit is not there :s
Ok. Let's start from the top.
The function to create the database is DB.Init(). Just declaring a function doesn't make it run. Are you making it run anywhere in your code?
[lua]
hook.Add( "InitPostEntity", "makedb", DB.Init )
[/lua]
Put that in there somewhere? It will run it when the server initializes
shall i put in init or cl_init or something?
[editline]02:25PM[/editline]
fuck i relised u had writ something abouv were u sed put that in there somewher but now i get this error
gamemode\data.lua:1: attempt to index global 'DB' (a nil value)
Sorry i copy pasted your function name, put the name of the function you want to call where I put the ***'s
hook.Add( "InitPostEntity", "makedb",*************** )
still get error
Perhaps at the top, put
[lua]local DB = {}[/lua]
ok i dont get any errors anymore but still dose not add to database :S
Sorry, you need to Log In to post a reply to this thread.