• Tried to use invalid object (type Panel) (Object was NULL or not of the right type)
    9 replies, posted
Okay, this has been stressing me for hours and i still can not find the problem. I am getting spammed with errors from the three lines lines that have DrawRect. These are what draw the buttons. This is the error: [CODE] [ERROR] STEAM_0:0:26148884/luapad/F3Menu.txt:45: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. __newindex - [C]:-1 2. unknown - STEAM_0:0:26148884/luapad/F3Menu.txt:45 [ERROR] STEAM_0:0:26148884/luapad/F3Menu.txt:65: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. __newindex - [C]:-1 2. unknown - STEAM_0:0:26148884/luapad/F3Menu.txt:65 [ERROR] STEAM_0:0:26148884/luapad/F3Menu.txt:86: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. __newindex - [C]:-1 2. unknown - STEAM_0:0:26148884/luapad/F3Menu.txt:86 [/CODE] Any help here would be greatly appreciated! Thanks a lot! [CODE] resource.AddFile("resouce/fonts/BebasNeue.otf") surface.CreateFont( "ButtonFont", { font = "BebasNeue", size = 30, weight = 500, antialias = true, } ) function ClosePanels() Frame:Close() Frame:Remove() end function CreateVGUIMenu() Frame = vgui.Create( "DFrame" ) local colorofossim1 = Color(200, 90, 90, 255) local colorofossim2 = Color(200, 90, 90, 255) local colorofossim3 = Color(200, 90, 90, 255) Frame:SetPos( ScrW()/2-250, 100 ) Frame:SetSize( 500, 360 ) Frame:SetDraggable( false ) Frame:ShowCloseButton( false ) Frame.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, 500, 360 ) end -----Button 1------- PSButton = vgui.Create( "DButton", Frame ); PSButton:SetSize( 300, 80 ); PSButton:SetPos(500/2-150, 30 ); PSButton:SetText( "" ); PSButton.DoClick = function() LocalPlayer():ConCommand("ps_shop"); ClosePanels() end PSButton.Paint = function() surface.SetDrawColor( colorofossim1 ) surface.DrawRect( 0, 0, 300, 80 ) CBLabel1 = vgui.Create( "DLabel", PSButton ) CBLabel1:SetPos( 300/2-44, 0 ) CBLabel1:SetSize(300, 80) CBLabel1:SetFont("ButtonFont") CBLabel1:SetText( "Pointshop" ) PSButton.OnCursorEntered = function() colorofossim1 = Color(230, 120, 120, 255) end PSButton.OnCursorExited = function() colorofossim1 = Color(200, 90, 90, 255) end end -----Button 2------- DonateButton = vgui.Create( "DButton", Frame ); DonateButton:SetSize( 300, 80 ); DonateButton:SetPos(500/2-150, 140 ); DonateButton:SetText( "" ); DonateButton.Paint = function() surface.SetDrawColor( colorofossim2 ) surface.DrawRect( 0, 0, 300, 80 ) CBLabel2 = vgui.Create( "DLabel", DonateButton ) CBLabel2:SetPos(300/2-32, 0 ) CBLabel2:SetSize(300, 80) CBLabel2:SetFont("ButtonFont") CBLabel2:SetText( "Donate" ) DonateButton.OnCursorEntered = function() colorofossim2 = Color(230, 120, 120, 255) end DonateButton.OnCursorExited = function() colorofossim2 = Color(200, 90, 90, 255) end end -----Button 3------- CloseButton = vgui.Create( "DButton", Frame ); CloseButton:SetSize( 300, 80 ); CloseButton:SetPos(500/2-150, 250 ); CloseButton:SetText( "" ); CloseButton.DoClick = function() ClosePanels() end CloseButton.Paint = function() surface.SetDrawColor( colorofossim3 ) surface.DrawRect( 0, 0, 300, 80 ) CBLabel3 = vgui.Create( "DLabel", CloseButton ) CBLabel3:SetPos( 300/2-25, 0 ) CBLabel3:SetSize(300, 80) CBLabel3:SetFont("ButtonFont") CBLabel3:SetText( "Close" ) CloseButton.OnCursorEntered = function() colorofossim3 = Color(230, 120, 120, 255) end CloseButton.OnCursorExited = function() colorofossim3 = Color(200, 90, 90, 255) end Frame:MakePopup() end end hook.Add( "Think", "MenuKeyListener", function() if ( input.IsKeyDown( KEY_F4 ) ) then CreateVGUIMenu() end end ) [/CODE]
[quote] function CreateVGUIMenu() Frame = vgui.Create( "DFrame" ) [/quote] .. Define Frame before all the code, [code] local Frame = {} [/code]
[QUOTE=sackcreator54;42484142].. Define Frame before all the code, [code] local Frame = {} [/code][/QUOTE] Still doing the same thing sadly :/
Move [code] Frame:Makepopup() [/code] ABOVE [code] -----Button 1------- [/code]
[QUOTE=sackcreator54;42484284]Move [code] Frame:Makepopup() [/code] ABOVE [code] -----Button 1------- [/code][/QUOTE] I meant to specify earlier but the problem is not when the menu comes up, its when i press close. The menu doesnt close and it just spams me with those 3 errors.
Don't use [code] Frame:Close() or Frame:Remove() [/code] Use [code] Frame:SetVisible(false) [/code] instead.
[code]function ClosePanels() Frame:Close() Frame:Remove() end[/code] Only use Frame:Remove() And make sure all of other your panels are local variables, not global, to avoid other scripts messing up those variables. Just in case.
[QUOTE=Robotboy655;42486763][code]function ClosePanels() Frame:Close() Frame:Remove() end[/code] Only use Frame:Remove() And make sure all of other your panels are local variables, not global, to avoid other scripts messing up those variables. Just in case.[/QUOTE] That works perfect. Thank you so much. The only problem that i am having now is when i press the key to open the VGUI, many VGUI's open. How would I go about solving this? Could i just check if it is already open, and how would I do that? Thanks a lot
This is becoming a huge obstacle for me. I have tried the most obvious things and its just not doing anything. Any help would be great.
[QUOTE=TheEncrypted;42493483]This is becoming a huge obstacle for me. I have tried the most obvious things and its just not doing anything. Any help would be great.[/QUOTE] [Code]if IsValid(Frame) then return end[/Code] Put that at top of CreateVGUIMenu. It'll avoid creating new frames if one already exists. You really should rename Frame to something else though.
Sorry, you need to Log In to post a reply to this thread.