[ERROR] gamemodes/test/gamemode/init.lua:26: attemp to call method 'databaseCheck' (a nil value)
1. Unknown - gamemodes/test/gamemode/init.lua:26
init.lua, 26 line:
function GM:PlayerAuthed( ply, steamID, uniqueID )
ply:databaseCheck()
end
function ply:databaseCheck()
self.database = {}
local f = self:databaseExists()
if f then
self:databaseRead()
else
self:databaseCreate()
end
self:databaseSend()
self:databaseNetworkedData()
end
Where is ply defined at when you define the ply:databaseCheck function? You probably don't actually have a handle of the player metatable. That or you have a startup error preventing that function from even being created.
Do you have the following snippet anywhere in that same source file?
local ply = FindMetaTable("Player")
local ply = FindMetaTable("Player")
util.AddMetworkString( "database" )
function ply:ShortenSteamId()local id = self:SteamID()
id = string.gsub(id, ":", "_")
return id
end
local oldPrint = print
local function print(s)
oldPrint("database.lua: " .. s)
end
function ply:databaseDefault()
self:databaseSetValue( "money", 100)
self:databaseSetValue( "xp", 0 )
self:databaseSetValue( "hunger", 0)
self:databaseSetValue( "thirsty", 0)
local i = {}
i["test1"] = { amount = 10 }
i["test2"] = { amount = 10 }
self:databaseSetValue( "inventory", i)
end
function ply:databaseNetworkedData()
local money = self:databaseGetValue( "money" )
local xp = self:databaseGetValue( "xp" )
local hunger = self:databaseGetValue( "hunger" )
local thirst = self:databaseGetValue( "thirsty" )
self:SetNWInt("money", money)
self:SetNWInt("xp", xp)
self:SetNWInt("hunger", hunger)
self:SetNWInt("thirsty", thirst)
self:KillSilent()
self:Spawn()
end
function ply:databaseFolders()
return "server/Fish&Hunt/players/" .. self:ShortSteamID() .. "/"
end
function ply:databasePath()
return self:databaseFolders() .. "database.txt"
end
function ply:databaseSet( tab )
self.database = tab
end
function ply:databaseGet()
return self.database
end
function ply:databaseCheck()
self.database = {}
local f = self:databaseExists()
if f then
self:databaseRead()
else
self:databaseCreate()
end
self:databaseSend()
self:databaseNetworkedData()
end
function ply:databaseSend()
net.Start( "database" )
net.WriteTable( self:databaseGet() )
net.Send ( self )
end
function ply:databaseExists()
local f = file.Exists(self:databasePath(), "DATA")
return f
end
function ply:databaseRead()
local str = file.Read(self:databasePath(), "DATA")
self:databaseSet( util.KeyValuesToTable(str) )
end
function ply:databaseSave()
local str = util.TableToKeyValues(self.database)
local f = file.Write(self:databasePath(), str)
self:databaseSend()
end
function ply:databaseCreate()
self:databaseDefault()
local b = file.CreateDir( self:databaseFolders() )
self:databaseSave()
end
function ply:databaseDisconnect()
self:databaseSave()
end
function ply:databaseSetValue( name, v)
if not v then return end
if type(v) == "table" then
if name = "inventory" then
for k,b in pairs(v) do
if b, amount <= 0 then
v[k] = nil
end
end
end
local d = self.databaseGet()
d[name] = v
self:databaseSave()
end
function ply:databaseGetValue( name )
local d = self:databaseGet()
return d[name]
end
This looks good to me, so is there any startup error in this file or whatever file includes it? Or, are you sure this file is being loaded at all? Add a naked print at the top of this file to check.
util.AddMetworkString( "database" )
proofreading is important
I fix it.
util.AddNetworkString( "database" )
Mhm.
So.. it still isn't working? Same error?
You still have Lua errors on startup if you're still getting the error in your OP. We need those to help.
only
[ERROR] gamemodes/test/gamemode/init.lua:26: attemp to call method 'databaseCheck' (a nil value)
1. Unknown - gamemodes/test/gamemode/init.lua:26
"attemp to call" ???
Anyway, what's your line 26 and a couple lines surrounding?
He has to still have a startup error in his other file that contains ply:databaseCheck that he's missing. That or it isn't being loaded period.
init.lua, line 26:
function GM:PlayerAuthed( ply, steamID, uniqueID )
ply:databaseCheck()
end
function ply:databaseCheck()
self.database = {}
local f = self:databaseExists()
if f then
self:databaseRead()
elseself:databaseCreate()
end
self:databaseSend()
self:databaseNetworkedData()
end
Sorry, you need to Log In to post a reply to this thread.