VGUI Errors?

Hey!
Excuse my ignorance but I am having a few issues with LUA and Gmod.
I have tried to make a DFrame in lua but when I run it in Gmod I get this error:
[ERROR] lua/mymod.lua:3: attempt to index global ‘vgui’ (a nil value) 1. unknown - lua/mymod.lua:3 ]

Heres my code:
print(“Test”);
local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 200,500 )
DermaPanel:SetSize( 500, 600 )
DermaPanel:SetTitle( “Menu” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( false )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

Any ideas as to whats going on?
I use lua_openscript myMod.lua to run the lua file. I have tried lua_openscript_cl but still nothing.

Yea, try to run the script clientside instead.

Any ideas as to how I would go about doing that?
I have tried the lua_openscript_cl but It doesn’t do anything.
Any ideas?
Thanks.

I’m having this same problem. After seeing this thread and the answer from Garry, I’m starting to think the error is something obvious. Still, I’m new to Lua and can’t find out how to fix it. I’m using the very same sample of code from the Gmod Wiki:



function TestVGUI( )
 
    local DermaPanel = vgui.Create( "DFrame" )  // Create the frame in a local variable
DermaPanel:SetPos( 100, 100 )               // Set the position to 100, 100 ( x, y )
DermaPanel:SetSize( 300, 200 )              // Set the size to 300, 200 pixels
DermaPanel:SetTitle( "My new Derma frame" ) // Set the title
DermaPanel:SetVisible( true )               // Can you see it? ( Optional - default true )
DermaPanel:SetDraggable( true )             // Can you move/drag it? ( optional - default true )
DermaPanel:ShowCloseButton( true )          // Can you see the close button ( reccomended ) ( optional - default true )
DermaPanel:MakePopup()                    // Make it popup

	end

concommand.Add( "testvgui", TestVGUI );


After running testvgui on console I get the same error as OP.

as wizard said a month ago haha, make sure it is clientside

lua/autorun/client/yourscript.lua
place the code in there, that way it automatically runs, then try “testvgui” in console again

if you put it in lua/autorun/yourscript.lua it would be ran as a ‘shared’ file, because VGUI is only clientside you would do


function TestVGUI( )
    if CLIENT then
    local DermaPanel = vgui.Create( "DFrame" )  // Create the frame in a local variable
DermaPanel:SetPos( 100, 100 )               // Set the position to 100, 100 ( x, y )
DermaPanel:SetSize( 300, 200 )              // Set the size to 300, 200 pixels
DermaPanel:SetTitle( "My new Derma frame" ) // Set the title
DermaPanel:SetVisible( true )               // Can you see it? ( Optional - default true )
DermaPanel:SetDraggable( true )             // Can you move/drag it? ( optional - default true )
DermaPanel:ShowCloseButton( true )          // Can you see the close button ( reccomended ) ( optional - default true )
DermaPanel:MakePopup()                    // Make it popup

    end
concommand.Add( "testvgui", TestVGUI ) //gmod wiki says concommand is a shared function
end

as you might imagen, lua/autorun/server/yourscript.lua would be purely for serverside functions, so you wouldn’t put a VGUI script in there
cheers!

Well the thing is, I’m using that code for a gamemode, and it is in cl_init.lua. From what I learned cl_init is what runs clientside code isn’t it? :S

[editline]24th December 2012[/editline]

Also, I tried moving concommand to shared.lua since you said it’s a shared function that’s what I thought was correct doing. Ended up with testvgui as an unknown command.

If you send cl_init.lua to the client, yes. You have to use AddCSLuaFile().

In init.lua there is already this:


AddCSLuaFile( "cl_init.lua" )

Ok so after a somewhat long search I have found that all my concommand.Add should be on my shared.lua (like Watercycle said in his code example) and that I should not include my cl_init.lua in my init.lua.

Now I have a problem, all of my console commands that I created (like testvgui) through concommand.Add are unknown.

In my init.lua I have:
[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )[/lua]

I put the code example that Watercycle gave me in lua/autorun/test.lua and I get unknown command for “testvgui” anyway.

Only way I can get my condommand.Add commands to actually run functions is by placing them in my init.lua.

Anyone willing to give a hand here?

Any help would be really appreciated, this is kinda holding me back on my first gamemode development.

[editline]25th December 2012[/editline]

So, me and a friend are taking a look at this and learning as we go. What happens is he also tried to make a Derma Panel base and his works and mine doesn’t. Now what fascinates me the most is that our code is identical basicly.

Mine is:
[lua]
local function wawlol()
local DermaPanel = vgui.Create( “DFrame” ) // Create the frame in a local variable
DermaPanel:SetPos( 100, 100 ) // Set the position to 100, 100 ( x, y )
DermaPanel:SetSize( 300, 200 ) // Set the size to 300, 200 pixels
DermaPanel:SetTitle( “My new Derma frame” ) // Set the title
DermaPanel:SetVisible( true ) // Can you see it? ( Optional - default true )
DermaPanel:SetDraggable( true ) // Can you move/drag it? ( optional - default true )
DermaPanel:ShowCloseButton( true ) // Can you see the close button ( reccomended ) ( optional - default true )
DermaPanel:MakePopup() // Make it popup
end

concommand.Add( “waw”, wawlol )
[/lua]

And his is:
[lua]
local function testone()
local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 250, 250 )
DermaPanel:SetTitle( “Testing Derma Stuff” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
end

concommand.Add( “testone”, testone )[/lua]

As you can see I even tried changing my function name but with no success.

The code is in a lua file which is in lua/autorun (shared).