• LUA global index error
    4 replies, posted
Well I'm coding a gamemode (name to be released soon) and I use abit of code from gmod wiki lua and theres an error. Link to the gmod wiki lua code. It's trying to index a global variable but I specifically say "local". Error (gamemode name stared out): ****\gamemode\cl_init.lua:11: attempt to index global 'vgui' (a nil value) The File LUA Code (of which it occurs): [url]http://pastebin.com/m79f2c601[/url] Many Thanks, Frosty.
Try this: [lua]include( 'shared.lua' ) include( 'cl_scoreboard.lua' ) include( 'cl_hud.lua' ) // Clientside only stuff goes here --Set Team Menu Start function set_team() if SERVER then return end local frame = vgui.Create( "DFrame" ) frame:SetPos( 100, ScrH() / 2 ) frame:SetSize( 200, 210 ) //Set the size frame:SetTitle( "Select Team" ) //Set title frame:SetVisible( true ) frame:SetDraggable( false ) frame:ShowCloseButton( true ) frame:MakePopup() team_1 = vgui.Create( "DButton", frame ) team_1:SetPos( 30, 30 ) team_1:SetSize( 100, 50 ) team_1:SetText( "Team Red" ) team_1.DoClick = function() //Make the player join team 1 RunConsoleCommand( "team_1" ) end team_2 = vgui.Create( "DButton", frame ) team_2:SetPos( 30, 85 ) //Place it next to our previous one team_2:SetSize( 100, 50 ) team_2:SetText( "Team Blue" ) team_2.DoClick = function() //Make the player join team 2 RunConsoleCommand( "team_2" ) end team_3 = vgui.Create( "DButton", frame ) team_3:SetPos( 30, 140 ) //Place it next to our previous one team_3:SetSize( 100, 50 ) team_3:SetText( "Spectator" ) team_3.DoClick = function() //Make the player join team 3 RunConsoleCommand( "team_3" ) end end concommand.Add( "team_menu", set_team ) --Set Team Menu End[/lua] If that fails (Which it really shouldn't), put [lua]local vgui = vgui[/lua] That is probably futile, but in the end it would speed up the running speed of the code by tiny amount - although you shouldn't be getting nil vgui errors on the client in the first place.
thanks, yes I know it's all wierd, I'll let you know if it works! [editline]03:23PM[/editline] nope none of the suggested fixes worked :/ I'm very annoyed and please someone help!
In your init.lua did you include() cl_init.lua? That would cause this problem. You must only AddCSLuaFile() it.
thankyou so much it worked, i was down as include, I've changed it, thanks again! Frosty.
Sorry, you need to Log In to post a reply to this thread.