I’m kind of a newbie to Lua coding, so I am currently doing a little project on Lua to get to know it better. The issue appeared when I came up to VGUI, actually trying to run a quick ‘test’ of some functions. I used a small snippet of code from the VGUI tutorial on wiki (http://wiki.garrysmod.com/?title=Lua:VGUI_Basics). However, it didn’t work giving me an error of ( [lua\autorun\vguitests.lua:4] attempt to index global ‘vgui’ (a nil value) ). Does that mean that the VGUI lib doesn’t somehow initialize on my GMod (I tried running the script both clientside and serverside). So uhm, here is the code I used (I have put it into “lua\autorun”, obviusly):
[lua]function TestVGUI( )
local Frame = vgui.Create( "Frame" ) Frame:SetSize( 200, 200 ) Frame:SetPos( 100, 100 ) Frame:SetVisible( true ) Frame:MakePopup( ) Frame:PostMessage( "SetTitle", "text", "This is the title" ) local Button = vgui.Create( "Button", Frame ) Button:SetText( "Click me!" ) Button:SetPos( 30, 5 ) Button:SetWide( 100 ) function Button:DoClick( ) self:SetText( "Clicked" ) end
concommand.Add( “testvgui”, TestVGUI )[/lua]
I would greatly appreciate if you reply.