ULX

Author Topic: Using XLib in XGUI settings module  (Read 2512 times)

0 Members and 2 Guests are viewing this topic.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Using XLib in XGUI settings module
« on: June 19, 2015, 06:35:05 AM »
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:
Code: [Select]
[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:
Code: [Select]
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" )
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Using XLib in XGUI settings module
« Reply #1 on: June 23, 2015, 06:44:20 PM »
Not sure if you've solved this or not, but the error you posted is coming from "addons/ulx/lua/ulx/modules/cl/utimesettings.lua:1", which is a different (and incorrect) path from where you said the xgui addon code should be, which is "/addons/utime-xgui-settings/lua/ulx/xgui/settings/cl_utimesettings.lua".

Double check that and I will try and help you further. If you do have/need both files, you should probably make sure all xlib-related code stays in the xgui/settings/cl_utimesettings.lua file.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Using XLib in XGUI settings module
« Reply #2 on: June 24, 2015, 09:31:55 PM »
Well, it turns out I just made a stupid mistake. Thanks for pointing out the discrepancy in the file paths Stickly Man! Turns out I had left a copy of the addon in addons/ulx/lua/ulx/modules/cl/utimesettings.lua while testing where to place the file, and just never deleted it.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Using XLib in XGUI settings module
« Reply #3 on: June 25, 2015, 08:16:03 AM »
Glad you got it figured out! ;D
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6