Code error?

Hello

I’m having an error with a script due to the sv_config and config not being included


 [ERROR] addons/skilltree/lua/vgui/skillpane.lua:217: attempt to index field 'Config' (a nil value)
  1. CheckCol - addons/skilltree/lua/vgui/skillpane.lua:217
   2. unknown - addons/skilltree/lua/vgui/skillpane.lua:199 

It’s supposed to execute a line of code but it requires the config and sv_config to be included.
I tried include(“sv_config”), include(“config”) but nothing seems to work. I don’t know how to do this. any help?

If the file is called sv_config.lua it’s only meant to be used serverside, unless you just named it that. When including files you’ll have to write the entire filename ex: sv_config.lua and unless it’s in the autorun folder, you’ll also need to AddCSLua(“myfile.lua”) in a serverside file for it to be available on the client.

I did include the .lua in the actual script. Its the vgui folder thats giving errors. I need to include config.lua (sv_config is not needed my mistake) but I already tried AddCSLuaFile and include in both files. For the vgui script, it gives an error saying config.lua is nil and when in config, it makes no difference.

You need to provide some code.


 -- skillpane.lua 
PANEL = {}

surface.CreateFont( "SkillTree_Skill", {size = 50,weight = 0,italic = true} )
surface.CreateFont( "SkillTree_Desc", {size = 18, italic = true} )

PANEL.desc = nil
PANEL.desci = 0
PANEL.panx = 0
PANEL.pany = 0
PANEL.maxpanx = 1000
PANEL.maxpany = 1000
PANEL.dragging = false
PANEL.mousex = 0
PANEL.mousey = 0
PANEL.dragstartx = 0
PANEL.dragstarty = 0

PANEL.lastskillup = 0
PANEL.lastskillupskill = 0

PANEL.sliderpos = 0
PANEL.sliderrate = 5

function PANEL:Paint(w,h)
	if SKILLTREE.BackgroundMode == SKILLTREE.IMAGEBACKGROUND then
		surface.SetMaterial(SKILLTREE.BACKGROUND)
		surface.SetDrawColor(Color(255,255,255))
		surface.DrawTexturedRect(0,0,w,h)
	else
		surface.SetDrawColor( SKILLTREE.BackgroundColor )
		surface.DrawRect( 0, 0, w, h )
	end
	self:Render(w, h)
	
	if self.desc != nil then
		self:DrawDescBox(self.desc.Desc,self.desc.x-self.panx+200,self.desc.y-self.pany+75)
		self:DrawDescBox(SKILLTREE.DATA.Skills[self.desci].."/"..self.desc.MaxRank,self.desc.x-self.panx+100,self.desc.y-self.pany+75)
	end
	
	surface.SetDrawColor(Color(128,128,128,255))
	surface.DrawRect(w-self.sliderpos+5,0,w/3,h)
	if self.sliderpos > 32 then
		for k, v in pairs(SKILLTREE.HelpText) do
			draw.SimpleText(v, "SkillTree_Desc", w-self.sliderpos/2, k*14, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		end
	end
end

function PANEL:Render(wo, ho)
	for k, v in pairs(SKILLTREE.Config.Skills) do
		if v.Parent != nil then
			local parent = SKILLTREE.Config.Skills[v.Parent]
			if self:InView(v.x,v.y) or self:InView(parent.x,parent.y) then
				surface.SetDrawColor(SKILLTREE.LineColor)
				surface.DrawLine(v.x-self.panx+100,v.y-self.pany+37,parent.x-self.panx+100,parent.y-self.pany+37)
				if SKILLTREE:PlayerHasPrerequisites(v) then
				surface.DrawCircle(v.x-self.panx+100+SKILLTREE.Vectors[k][1]*(CurTime()%SKILLTREE.OrbEffectTime),v.y-self.pany+37+SKILLTREE.Vectors[k][2]*(CurTime()%SKILLTREE.OrbEffectTime),4,SKILLTREE.LineColor)
				end
			end
		end
	end
	for k, v in pairs(SKILLTREE.Config.Skills) do
		if self:InView(v.x,v.y) then
			self:DrawSkill(v)
		end
	end
end

function PANEL:DrawDescBox(text,x,y)
	surface.SetFont("SkillTree_Desc")
		local tw, th = surface.GetTextSize(text)
		draw.RoundedBox(8,x-4,y-2,tw+8,th+4,Color(0,0,0,192))
		draw.SimpleText(text,"SkillTree_Desc",x,y,SKILLTREE.DescColor)
end

function PANEL:DrawSkill(tab)
	local index = table.KeyFromValue(SKILLTREE.Config.Skills,tab)
	local rank = SKILLTREE.DATA.Skills[index]
	/*
	surface.SetDrawColor(SKILLTREE.SkillBorderColor)
	surface.DrawRect(tab.x-self.panx-2,tab.y-self.pany-2,204,79)*/
	draw.RoundedBox(8,tab.x-self.panx-2,tab.y-self.pany-2,204,79,SKILLTREE.SkillBorderColor)
	local draw1 = false
	local draw2 = false
	if SKILLTREE:PlayerHasPrerequisites(tab) then
		if rank != tab.MaxRank then
			/*
			surface.SetDrawColor(SKILLTREE.AvailableSkillColor)
			surface.DrawRect(tab.x-self.panx,tab.y-self.pany,200,75)*/
			draw.RoundedBox(8,tab.x-self.panx,tab.y-self.pany,200,75,SKILLTREE.AvailableSkillColor)
		end
		if rank > 0 then
			/*
			surface.SetDrawColor(SKILLTREE.MaxedSkillColor)
			surface.DrawRect(tab.x-self.panx,tab.y-self.pany,rank/tab.MaxRank*200,75)*/
			if self.lastskillupskill == index and CurTime() - self.lastskillup < 2 then
				draw.RoundedBox(8,tab.x-self.panx,tab.y-self.pany,rank/tab.MaxRank*200,75,self:GetBrightenedColor(SKILLTREE.MaxedSkillColor,(1 - (CurTime()-self.lastskillup))  ))
			else
				draw.RoundedBox(8,tab.x-self.panx,tab.y-self.pany,rank/tab.MaxRank*200,75,SKILLTREE.MaxedSkillColor)
			end
		end
		/*
		if rank > 0 and rank < tab.MaxRank then
			surface.SetDrawColor(self:GetDegradedColor(self:GetBlendedColor(SKILLTREE.MaxedSkillColor,SKILLTREE.AvailableSkillColor),1.25))
			surface.DrawRect(tab.x-self.panx+rank/tab.MaxRank*200-4,tab.y-self.pany,4,75)
		end*/
		draw.SimpleText(tab.Name,"SkillTree_Skill",tab.x-self.panx+100,tab.y-self.pany+37,SKILLTREE.SkillTitleColor,TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
	else
		/*
		surface.SetDrawColor(SKILLTREE.UnavailableSkillColor)
		surface.DrawRect(tab.x-self.panx,tab.y-self.pany,200,75)*/
		draw.RoundedBox(8,tab.x-self.panx,tab.y-self.pany,200,75,SKILLTREE.UnavailableSkillColor)
		draw.SimpleText(tab.Name,"SkillTree_Skill",tab.x-self.panx+100,tab.y-self.pany+37,self:GetDegradedColor(SKILLTREE.SkillTitleColor,0.5),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
	end
end

function PANEL:GetBrightenedColor(col,amt)
	return Color(col.r + (255 - col.r)*amt,col.g + (255 - col.g)*amt,col.b + (255 - col.b)*amt)
end

function PANEL:GetBlendedColor(col,col2)
	return Color(col.r/2+col2.r/2,col.g/2+col2.g/2,col.b/2+col2.b/2)
end

function PANEL:GetDegradedColor(col,amt)
	return Color(col.r*amt,col.g*amt,col.b*amt)
end

function PANEL:InView(x, y)
	local w, h = self:GetSize()
	
	if ((x+200 > self.panx) and (y+75 > self.pany) and (x < self.panx+w) and (y < self.pany+h)) then
		return true
	end
	return false
end

function PANEL:OnMousePressed( mousecode )
	local x, y = gui.MousePos()
	if mousecode == 107 then 
		self.dragstartx = x
		self.dragstarty = y
		self.mousex = x
		self.mousey = y
		self.dragging = true
		self.desc = nil
		self:MouseCapture(true)
	end
end

function PANEL:OnMouseReleased( mousecode )
	local x, y = gui.MousePos()
	if mousecode == 107 then
		if x == self.dragstartx and y == self.dragstarty then
			self:OnMouseClicked(x,y)
		end
		self.dragging = false
		self:MouseCapture(false)
	end
end

function PANEL:OnMouseClicked(x,y)
	local tab, i = self:CheckCol(x,y)
	if tab!=nil and SKILLTREE.DATA.freepoints >= 1 and SKILLTREE.DATA.Skills* < tab.MaxRank then
		if SKILLTREE:PlayerHasPrerequisites(tab) then
			SKILLTREE.DATA.freepoints = SKILLTREE.DATA.freepoints - 1
			SKILLTREE.DATA.Skills* = SKILLTREE.DATA.Skills*+1
			self.lastskillup = CurTime()
			self.lastskillupskill = i
			surface.PlaySound("buttons/button14.wav")
			net.Start("skilltree_updatepacket")
				net.WriteInt(i,16)
			net.SendToServer()
		else
			surface.PlaySound("buttons/button16.wav")
		end
	end
end

function PANEL:Think()
	local x, y = gui.MousePos()
	local w, h = self:GetSize()
	
	local slider = -1
	if x > ScrW()/6*5 - 32 and x < ScrW()/6*5 - 8 and not self.dragging then
		slider = 1
	end
	self:SliderThink(slider,w)
	
	if self.dragging then
		self.panx = math.max(math.min( self.panx+(self.mousex-x),self.maxpanx),0)
		self.pany = math.max(math.min( self.pany+(self.mousey-y),self.maxpany),0)
		self.mousex = x
		self.mousey = y
	else
		local tab, i = self:CheckCol(x,y)
		if tab!=nil then
			self.desc = tab
			self.desci = i
		else
			self.desc = nil
		end
	end
end

function PANEL:SliderThink(bool,w)
	self.sliderpos = math.max(math.min(self.sliderpos + bool*self.sliderrate,w/3),32)
end

function PANEL:CheckCol(xa,ya)
	if (xa>ScrW()/6+8 and xa<ScrW()/6*5-8 and ya>ScrH()/6-4 and ya<ScrH()/6*5+16) then 
		local x = xa - (ScrW()/6+8)
		local y = ya - (ScrH()/6-4)
		for k, v in pairs(SKILLTREE.Config.Skills) do
			if x>v.x-self.panx and y>v.y-self.pany and x<v.x-self.panx+200 and y<v.y-self.pany+75 then
				return v, k
			end
		end
	end
	return nil
end

derma.DefineControl( "SkillTree", "A Skill Tree", PANEL, "DPanel" ) 


 --config.lua

include("vgui/skillpane.lua")

SKILLTREE.Config = {}
SKILLTREE.Config.Skills = {}
SKILLTREE.Config.Types = {}

SKILLTREE.Config.Types = {"spawn","hit","attacked","death","kill","tick"}

SKILLTREE.Config.Skills[0] = {Name = "Vitality I", Type = "spawn", Desc = "Increases your health by 3/rank", MaxRank = 3, x = 100, y = 100, func = function( ply ) 
	local inc = ply.SKILLTREE.Skills[0]*3
	ply:SetMaxHealth( ply:GetMaxHealth() + inc )
	ply:SetHealth( ply:Health() + inc ) 
end}

SKILLTREE.Config.Skills[1] = {Name = "Agility I", Type = "spawn", Desc = "Increases your movement speed by 10", MaxRank = 1, x = 400, y = 100, func = function( ply ) 
	ply:SetWalkSpeed( ply:GetWalkSpeed()+10 ) 
	ply:SetRunSpeed( ply:GetRunSpeed()+10 )
end}

SKILLTREE.Config.Skills[2] = {Name = "Vitality II", Type = "spawn", Desc = "Increases your health by 10", MaxRank = 1, Parent = 0, x = 100, y = 250, func = function( ply )
	ply:SetMaxHealth( ply:GetMaxHealth()+10 )
	ply:SetHealth( ply:Health()+10 )
end}

SKILLTREE.Config.Skills[3] = {Name = "Agility II", Type = "spawn", Desc = "Increases your jumping power by 10", MaxRank = 1, Parent = 1, x = 400, y = 250, func = function( ply )
	ply:SetJumpPower( ply:GetJumpPower()+10 )
end}

SKILLTREE.Config.Skills[4] = {Name = "Sturdy", Type = "attacked", Desc = "Reduces incoming damage by 2%/rank", MaxRank = 5, Parent = 1, x = 700, y = 250, func = function( ply, dmg )
	dmg:ScaleDamage( 1 - 0.02 * ply.SKILLTREE.Skills[4] )
end}

SKILLTREE.Config.Skills[5] = {Name = "Brutality", Type = "hit", Desc = "Increases all damage dealt by 2", MaxRank = 1, Parent = 4, x = 700, y = 400, func = function( attacker, ply, dmg )
	dmg:AddDamage(2)
end}

print("SkillTree Config Loaded") 

[editline]1st September 2014[/editline]

The code works but the problem is how config will be included in a vgui script