Hey guys, im making a gamemode and the vgui is giving this error: CTC\gamemode\cl_init.lua:5: attempt to index global 'vgui' (a nil value)
heres the code:
local frame = vgui.Create( "Frame" )
frame:SetPos( ScrW() / 4, ScrH() / 4)
frame:SetSize( 500, 500 )
frame:PostMessage( "SetTitle", "text", "Coose Team" )
frame:SetVisible( true )
frame:ShowCloseButton ( false )
frame:MakePopup ()
local team_1 = vgui.Create( "Button", frame )
team_1:SetPos( 100, 430 )
team_1:SetSize( 100, 50 )
team_1:SetText( "Noobs" )
team_1.DoClick = function()
frame:Close()
RunConsoleCommand( "team_1" )
end
local team_2 = vgui.Create( "Button", frame )
team_2:SetPos( 300, 430 )
team_2:SetSize( 100, 50 )
team_2:SetText( "Combine" )
team_2.DoClick = function()
frame:Close()
RunConsoleCommand( "team_2" )
end
You are calling the vgui function with nil parameters.
[code]
local frame = vgui.Create( "DFrame" )
frame:SetPos( ScrW() / 4, ScrH() / 4)
frame:SetSize( 500, 500 )
frame:PostMessage( "SetTitle", "text", "Choose Team" )
frame:SetVisible( true )
frame:ShowCloseButton ( false )
frame:MakePopup ()
local team_1 = vgui.Create( "DButton", frame )
team_1:SetPos( 100, 430 )
team_1:SetSize( 100, 50 )
team_1:SetText( "Noobs" )
team_1.DoClick = function()
frame:Close()
RunConsoleCommand( "team_1" )
end
local team_2 = vgui.Create( "DButton", frame )
team_2:SetPos( 300, 430 )
team_2:SetSize( 100, 50 )
team_2:SetText( "Combine" )
team_2.DoClick = function()
frame:Close()
RunConsoleCommand( "team_2" )
end [/code]
[lua] local frame = vgui.Create( "Frame" ) [/lua]
it should be
[lua] local frame = vgui.Create( "DFrame" ) [/lua]
[lua] local team_1 = vgui.Create( "Button", frame )[/lua]
It should be
[lua] local team_1 = vgui.Create( "DButton", frame ) [/lua]
Also if you need any help look here [url]http://wiki.garrysmod.com/?title=Guide_to_Derma[/url].
[QUOTE=Whitefox08;16085367][lua] local frame = vgui.Create( "Frame" ) [/lua]
it should be
[lua] local frame = vgui.Create( "DFrame" ) [/lua]
local team_1 = vgui.Create( "Button", frame )
It should be
[lua] local team_1 = vgui.Create( "DButton", frame ) [/lua][/QUOTE]
Same error :/
Are you trying to parent it to the panel with , frame?
If so use [lua]team_1:SetParent(frame)[/lua]
instead of doing vgui.Create("DButton", frame)
[QUOTE=Whitefox08;16085476]Are you trying to parent it to the panel with , frame?
If so use [lua]team_1:SetParent(frame)[/lua]
instead of doing vgui.Create("DButton", frame)[/QUOTE]
Still giveing:
CTC\gamemode\cl_init.lua:5: attempt to index global 'vgui' (a nil value)
Code now:
function set_team()
local frame = vgui.Create( "DFrame" )
frame:SetPos( ScrW() / 4, ScrH() / 4)
frame:SetSize( 500, 500 )
frame:SetTitle( "Coose Team" )
frame:SetVisible( true )
frame:ShowCloseButton ( false )
frame:MakePopup ()
team_1 = vgui.Create( "DButton", frame )
team_1:SetPos( 100, 430 )
team_1:SetSize( 100, 50 )
team_1:SetText( "Noobs" )
team_1:SetParent(frame)
team_1.DoClick = function()
frame:Close()
RunConsoleCommand( "team_1" )
end
team_2 = vgui.Create( "DButton", frame )
team_2:SetPos( 300, 430 )
team_2:SetSize( 100, 50 )
team_2:SetText( "MingeBags" )
team_2:SetParent(frame)
team_2.DoClick = function()
frame:Close()
RunConsoleCommand( "team_2" )
end
function frame:Paint()
surface.SetDrawColor( 130, 130, 130, 255 )
surface.DrawRect( 0, 0, frame:GetWide(), frame:GetTall() )
end
function team_1:Paint()
surface.SetDrawColor( 0, 255, 0, 255 )
surface.DrawRect( 0, 0, team_1:GetWide(), team_1:GetTall() )
end
function team_2:Paint()
surface.SetDrawColor( 255, 255, 0, 255 )
surface.DrawRect( 0, 0, team_2:GetWide(), team_2:GetTall() )
end
end
[editline]01:19AM[/editline]
What am i doing wrong?
Are you running it serverside?
AFAIK vgui's are all clientside only.
[QUOTE=BastinkaLive;16098775]Are you running it serverside?
AFAIK vgui's are all clientside only.[/QUOTE]
Yea its client side
I'll try and load it in my Garrysmod, get back to you in a bit.
E:
[lua]function set_team()
local frame = vgui.Create( "DFrame" )
frame:Center()
frame:SetSize( 500, 500 )
frame:SetTitle( "Coose Team" )
frame:SetVisible( true )
frame:ShowCloseButton ( false )
frame:MakePopup ()
team_1 = vgui.Create( "DButton", frame )
team_1:SetPos( 100, 430 )
team_1:SetSize( 100, 50 )
team_1:SetText( "Noobs" )
team_1.DoClick = function()
frame:Close()
RunConsoleCommand( "team_1" )
end
team_2 = vgui.Create( "DButton", frame )
team_2:SetPos( 300, 430 )
team_2:SetSize( 100, 50 )
team_2:SetText( "MingeBags" )
team_2.DoClick = function()
frame:Close()
RunConsoleCommand( "team_2" )
end
end[/lua]
Works fine for me, I just removed the paint functions.
Sorry, you need to Log In to post a reply to this thread.