I made a settings panel for UTime, and it works fine if it is in the actual ulx addon folder. However when I try to package it as it's own addon it give me a console error saying that it 'xlib' is a nil value. This is strange to me because I had a look at another XGUI settings panel (Apple's XGUI version of autopromote) and it doesn't seem to do anything special in order to use xlib functions, but it doesn't give me any console errors. The even weirder thing is that my addon seems to work fine, even with the error.
Full error:
[ERROR] addons/ulx/lua/ulx/modules/cl/utimesettings.lua:1: attempt to index global 'xlib' (a nil value)
1. unknown - addons/ulx/lua/ulx/modules/cl/utimesettings.lua:1
2. include - [C]:-1
3. unknown - addons/ulx/lua/ulx/cl_init.lua:12
4. include - [C]:-1
5. unknown - addons/ulx/lua/ulib/modules/ulx_init.lua:4
6. include - [C]:-1
7. unknown - addons/ulib/lua/ulib/cl_init.lua:23
8. include - [C]:-1
9. unknown - addons/ulib/lua/autorun/ulib_init.lua:5
Full addon code, located in /addons/utime-xgui-settings/lua/ulx/xgui/settings/cl_utimesettings.lua:
local utimepnl = xlib.makepanel{ parent=xgui.null }
function makeutimecolorpicker( t )
local pnl = vgui.Create( "xlibColorPanel", t.parent )
pnl:SetPos( t.x, t.y )
xlib.checkRepCvarCreated( t.repconvar .. "_r" )
xlib.checkRepCvarCreated( t.repconvar .. "_g" )
xlib.checkRepCvarCreated( t.repconvar .. "_b" )
local colR = GetConVar( t.repconvar .. "_r" ):GetInt()
local colG = GetConVar( t.repconvar .. "_g" ):GetInt()
local colB = GetConVar( t.repconvar .. "_b" ):GetInt()
pnl:SetColor( Color( colR, colG, colB ) )
function pnl.ConVarUpdated( sv_cvar, cl_cvar, ply, old_val, new_val )
if cl_cvar == t.repconvar .. "_r" then
pnl:SetColor( Color( new_val:GetInt(), colG, colB ) )
end
if cl_cvar == t.repconvar .. "_g" then
pnl:SetColor( Color( colR, new_val:GetInt(), colB ) )
end
if cl_cvar == t.repconvar .. "_b" then
pnl:SetColor( Color( colR, colG, new_val:GetInt() ) )
end
end
hook.Add( "ULibReplicatedCvarChanged", "XLIB_" .. t.repconvar, pnl.ConVarUpdated )
function pnl:OnChangeImmediate( color )
RunConsoleCommand( t.repconvar .. "_r", color.r )
RunConsoleCommand( t.repconvar .. "_g", color.g )
RunConsoleCommand( t.repconvar .. "_b", color.b )
end
end
xlib.makelabel{ x=10, y=5, label="Outside color:", parent=utimepnl }
makeutimecolorpicker{ x=10, y=20, repconvar="utime_outsidecolor", parent=utimepnl }
xlib.makelabel{ x=145, y=5, label="Inside color:", parent=utimepnl }
makeutimecolorpicker{ x=145, y=20, repconvar="utime_insidecolor", parent=utimepnl }
xlib.makelabel{ x=10, y=155, label="Outside text color:", parent=utimepnl }
makeutimecolorpicker{ x=10, y=170, repconvar="utime_outsidetext", parent=utimepnl }
xlib.makelabel{ x=145, y=155, label="Inside text color:", parent=utimepnl }
makeutimecolorpicker{ x=145, y=170, repconvar="utime_insidetext", parent=utimepnl }
xlib.makecheckbox{ x=280, y=5, w=150, label="Enable UTime window", convar="utime_enable", parent=utimepnl }
xlib.makelabel{ x=280, y=20, label="X Position:", parent=utimepnl }
xlib.makeslider{ x=280, y=30, w=160, label="<--->", min=0, max=100, decimal=1, repconvar="utime_pos_x", parent=utimepnl }
xlib.makelabel{ x=280, y=45, label="Y Position:", parent=utimepnl }
xlib.makeslider{ x=280, y=55, w=160, label="<--->", min=0, max=100, decmial=1, repconvar="utime_pos_y", parent=utimepnl }
xgui.addSubModule( "UTime Settings", utimepnl, nil, "client" )