Tables error, not understanding why it's happening.
8 replies, posted
Ok so, I'm getting the following errors:
[lua]
ERROR: GAMEMODE:'PlayerSpawn' Failed: gamemodes\trilogyrp\gamemode\init.lua:32: attempt to index global 'configuration' (a nil value)
gamemodes\trilogyrp\gamemode\configuration.lua:4: attempt to index global 'tgy' (a nil value)
[/lua]
And here is my files which those errors are based in
[b][highlight]Init.lua[/b][/highlight]
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
-- Define the trilogy( tgy ) table.
tgy = {}
include( 'configuration.lua' )
function tgy.Call( func )
return func()
end
function GM:PlayerLoadout( pl )
pl:GiveAmmo( 255, "Pistol", true )
pl:Give( "empty_weapon" )
end
function GM:PlayerInitialSpawn( pl )
self.BaseClass:PlayerInitialSpawn( pl )
print("(Tgy) - Player Initial Spawn called for: " .. pl:Nick() .. "." )
end
function GM:PlayerSpawn( pl )
self.BaseClass:PlayerSpawn( pl )
print("(Tgy) - Player Spawn called for: " .. pl:Nick() .. "." )
pl:SetModel( table.Random( configuration.PlayerModels.male ) )
print( pl:GetModel() )
end
[/lua]
[b][highlight]Configuration.lua[/b][/highlight]
[lua]
function InitializeConfiguration()
print("(Tgy) - Configuration file initialised.")
end
tgy.Call( InitializeConfiguration )
-- Server configuration.
configuration = {}
configuration.PlayerModels = {
male = {"models/Player/Group01/male_01.mdl", "models/Player/Group01/male_02.mdl", "models/Player/Group01/male_03.mdl"},
female = {"models/Player/Group01/female_01.mdl", "models/Player/Group01/female_02.mdl", "models/Player/Group01/female_03.mdl"}
[/lua]
A quick response would be excellent, I just don't understand why I'm getting this!
Don't include init.lua in configuration.lua
I was doing all that random stuff to try to get it to work. I'll remove it and try again,
[editline]01:44AM[/editline]
Same errors.
Male should be lowercase on line 32 in init.lua
Ok, I fixed that, but I'm still getting those errors.
[code]
gamemodes\trilogyrp\gamemode\configuration.lua:4: attempt to index global 'tgy' (a nil value)
: ERROR: GAMEMODE:'PlayerSpawn' Failed: gamemodes\trilogyrp\gamemode\init.lua:32: attempt to index global 'configuration' (a nil value)
[/code]
Place "include( 'configuration.lua' )" AFTER "tgy = {}"
Ok, that worked for defining the table. Now it's not finding the tgy.Call() function.
[code]
: gamemodes\trilogyrp\gamemode\configuration.lua:4: attempt to call field 'Call' (a nil value)
ERROR: GAMEMODE:'PlayerSpawn' Failed: gamemodes\trilogyrp\gamemode\init.lua:33: attempt to index global 'configuration' (a nil value)
[/code]
[editline]02:13AM[/editline]
I updated what the files look like in the OP.
[QUOTE=SchumacherAlt;22206301]Ok, that worked for defining the table. Now it's not finding the tgy.Call() function.
[/QUOTE]
Then place after defining this function...
[lua]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
-- Define the trilogy( tgy ) table.
tgy = {}
function tgy.Call( func )
return func()
end
include( 'configuration.lua' )
function GM:PlayerLoadout( pl )
pl:GiveAmmo( 255, "Pistol", true )
pl:Give( "empty_weapon" )
end
function GM:PlayerInitialSpawn( pl )
self.BaseClass:PlayerInitialSpawn( pl )
print("(Tgy) - Player Initial Spawn called for: " .. pl:Nick() .. "." )
end
function GM:PlayerSpawn( pl )
self.BaseClass:PlayerSpawn( pl )
print("(Tgy) - Player Spawn called for: " .. pl:Nick() .. "." )
pl:SetModel( table.Random( configuration.PlayerModels.male ) )
print( pl:GetModel() )
end[/lua]
Sorry, you need to Log In to post a reply to this thread.