• Button on my derma doesn't work.
    14 replies, posted
When I press the button on my derma, it gives me with error: [code] RunConsoleCommand: Command has invalid characters! (ent_create sent_sball (' ')) The first parameter of this function should contain only the command, the second parameter should contain arguments. [/code] Here's my Lua: [lua] local DermaButton1 = vgui.Create( "DButton" ) DermaButton1:SetParent( DermaPanel ) DermaButton1:SetText( "Ball" ) DermaButton1:SetPos( 20, 450 ) DermaButton1:SetSize( 150, 50 ) DermaButton1.DoClick = function () DermaButton1:SetText( "Done" ); RunConsoleCommand("ent_create sent_sball", ply) DermaPanel:SetVisible( false ) end end [/lua] Please help :ohdear:
First argument should only be the command: [lua]RunConsoleCommand("ent_create", "sent_sball")[/lua]
2 words. THANK YOU. [editline]04:07PM[/editline] :argh: it won't let me create another button: [code] autorun/client/poop.lua:23: attempt to index local 'DermaButton2' (a nil value) [/code] Here's my entire Lua... [lua] function BlahDerma() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50, 50 ) DermaPanel:SetSize( 500, 500 ) DermaPanel:SetTitle( "Item Menu" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) local DermaButton1 = vgui.Create( "DButton" ) DermaButton1:SetParent( DermaPanel ) DermaButton1:SetText( "Ball" ) DermaButton1:SetPos( 20, 50 ) DermaButton1:SetSize( 150, 50 ) DermaButton1.DoClick = function () DermaButton1:SetText( "Done" ); RunConsoleCommand("ent_create", "sent_sball") DermaPanel:SetVisible( false ) end end local DermaButton2 = vgui.Create( "DButton" ) DermaButton2:SetParent( DermaPanel ) DermaButton2:SetText( "God Mode" ) DermaButton2:SetPos( 20, 60 ) DermaButton2:SetSize( 150, 50 ) DermaButton2.DoClick = function () DermaButton2:SetTest( "Done"); RunConsoleCommand("give weapon", "weapon_bugbait") DermaPanel2:SetVisible( false ) end concommand.Add("testderma", BlahDerma) -- testderma is the command to open this panel function HideDerma() DermaPanel:SetVisible( false ) concommand:Add("hidetestderma", HideDerma) end [/lua]
Lol easy mistake :) You used a "end" to close the derma function, before you made DermaButton2. Should be: [lua] function BlahDerma() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50, 50 ) DermaPanel:SetSize( 500, 500 ) DermaPanel:SetTitle( "Item Menu" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) local DermaButton1 = vgui.Create( "DButton" ) DermaButton1:SetParent( DermaPanel ) DermaButton1:SetText( "Ball" ) DermaButton1:SetPos( 20, 50 ) DermaButton1:SetSize( 150, 50 ) DermaButton1.DoClick = function () DermaButton1:SetText( "Done" ); RunConsoleCommand("ent_create", "sent_sball") DermaPanel:SetVisible( false ) end local DermaButton2 = vgui.Create( "DButton" ) DermaButton2:SetParent( DermaPanel ) DermaButton2:SetText( "God Mode" ) DermaButton2:SetPos( 20, 60 ) DermaButton2:SetSize( 150, 50 ) DermaButton2.DoClick = function () DermaButton2:SetTest( "Done"); RunConsoleCommand("give weapon", "weapon_bugbait") DermaPanel2:SetVisible( false ) end end concommand.Add("testderma", BlahDerma) -- testderma is the command to open this panel function HideDerma() DermaPanel:SetVisible( false ) concommand:Add("hidetestderma", HideDerma) end [/lua] That should work I think
This is my current code: [lua] function Playermenu() DermaPanel1 = vgui.Create( "DFrame" ) DermaPanel1:SetPos( 50,25 ) DermaPanel1:SetSize( 500, 500 ) DermaPanel1:SetTitle( "Items" ) DermaPanel1:SetVisible( true ) DermaPanel1:SetDraggable( true ) DermaPanel1:ShowCloseButton( true ) DermaPanel1:MakePopup() local DermaButton = vgui.Create( "DButton", DermaPanel1 ) DermaButton:SetText( "Super Shorty" ) DermaButton:SetPos( 12.5, 30 ) DermaButton:SetSize( 100, 25 ) DermaButton.DoClick = function() RunConsoleCommand("give", "weapon_supershorty") end local DermaButton = vgui.Create( "DButton", DermaPanel1 ) DermaButton:SetText( "Baseball Bat" ) DermaButton:SetPos( 125.5, 30 ) DermaButton:SetSize( 100, 25 ) DermaButton.DoClick = function() RunConsoleCommand( "give", "weapon_bat" ) end end local DermaButton = vgui.Create( "DButton", Dermapanel1 ) DermaButton:SetText( "test" ) DermaButton:SetPos( 300, 30 ) DermaButton:SetSize( 100, 25 ) DermaButton.DoClick = function() RunConsoleCommand("give", "weapon_bugbait") end function Hidemenu() if DermaPanel1:IsVisible() == true then DermaPanel1:SetVisible(false) end end concommand.Add("matsmenu", Playermenu) concommand.Add("+matsmenu", Playermenu) concommand.Add("-matsmenu", Hidemenu) [/lua] And it doesn't work, I still get [code] autorun/client/poop.lua:30: attempt to index local 'DermaButton' (a nil value) [/code]
Did you read what I just said? You made the same mistake + you called all you buttons the same name (I dunno if it might mess up things, but I think it will) [lua] function Playermenu() DermaPanel1 = vgui.Create( "DFrame" ) DermaPanel1:SetPos( 50,25 ) DermaPanel1:SetSize( 500, 500 ) DermaPanel1:SetTitle( "Items" ) DermaPanel1:SetVisible( true ) DermaPanel1:SetDraggable( true ) DermaPanel1:ShowCloseButton( true ) DermaPanel1:MakePopup() local DermaButton1 = vgui.Create( "DButton", DermaPanel1 ) DermaButton:SetText( "Super Shorty" ) DermaButton:SetPos( 12.5, 30 ) DermaButton:SetSize( 100, 25 ) DermaButton.DoClick = function() RunConsoleCommand("give", "weapon_supershorty") end local DermaButton2 = vgui.Create( "DButton", DermaPanel1 ) DermaButton:SetText( "Baseball Bat" ) DermaButton:SetPos( 125.5, 30 ) DermaButton:SetSize( 100, 25 ) DermaButton.DoClick = function() RunConsoleCommand( "give", "weapon_bat" ) end local DermaButton3 = vgui.Create( "DButton", Dermapanel1 ) DermaButton:SetText( "test" ) DermaButton:SetPos( 300, 30 ) DermaButton:SetSize( 100, 25 ) DermaButton.DoClick = function() RunConsoleCommand("give", "weapon_bugbait") end end function Hidemenu() if DermaPanel1:IsVisible() == true then DermaPanel1:SetVisible(false) end end concommand.Add("matsmenu", Playermenu) concommand.Add("+matsmenu", Playermenu) concommand.Add("-matsmenu", Hidemenu) [/lua] That should work.
Sorry, I was typing my post as you posted I guess :ninja:'d. And your code still gets gets the error. [code] autorun/client/poop.lua:13: attempt to index global 'DermaButton' (a nil value) [/code]
[QUOTE=Chad Mobile;19861059]Sorry, I was typing my post as you posted I guess :ninja:'d. And your code still gets gets the error. [code] autorun/client/poop.lua:13: attempt to index global 'DermaButton' (a nil value) [/code][/QUOTE] Ahh sorry my mistake xD forgot to change after i rename a function so it whould work. here: [lua] function Playermenu() DermaPanel1 = vgui.Create( "DFrame" ) DermaPanel1:SetPos( 50,25 ) DermaPanel1:SetSize( 500, 500 ) DermaPanel1:SetTitle( "Items" ) DermaPanel1:SetVisible( true ) DermaPanel1:SetDraggable( true ) DermaPanel1:ShowCloseButton( true ) DermaPanel1:MakePopup() local DermaButton1 = vgui.Create( "DButton", DermaPanel1 ) DermaButton1:SetText( "Super Shorty" ) DermaButton1:SetPos( 12.5, 30 ) DermaButton1:SetSize( 100, 25 ) DermaButton1.DoClick = function() RunConsoleCommand("give", "weapon_supershorty") end local DermaButton2 = vgui.Create( "DButton", DermaPanel1 ) DermaButton2:SetText( "Baseball Bat" ) DermaButton2:SetPos( 125.5, 30 ) DermaButton2:SetSize( 100, 25 ) DermaButton2.DoClick = function() RunConsoleCommand( "give", "weapon_bat" ) end local DermaButton3 = vgui.Create( "DButton", Dermapanel1 ) DermaButton3:SetText( "test" ) DermaButton3:SetPos( 300, 30 ) DermaButton3:SetSize( 100, 25 ) DermaButton3.DoClick = function() RunConsoleCommand("give", "weapon_bugbait") end end function Hidemenu() if DermaPanel1:IsVisible() == true then DermaPanel1:SetVisible(false) end end concommand.Add("matsmenu", Playermenu) concommand.Add("+matsmenu", Playermenu) concommand.Add("-matsmenu", Hidemenu) [/lua]
The "test" button appears below the derma and doesnt move when I move the derma.
[QUOTE=Chad Mobile;19861122]The "test" button appears below the derma and doesnt move when I move the derma.[/QUOTE] Try change the pos of it?
I did change its postion, but its BELOW the derma like layers. Like underneath it.
[QUOTE=Chad Mobile;19861164]I did change its postion, but its BELOW the derma like layers. Like underneath it.[/QUOTE] Ohh. Sorry don't know how to fix that :S [editline]06:34PM[/editline] Fixed it. [lua] function Playermenu() DermaPanel1 = vgui.Create( "DFrame" ) DermaPanel1:SetPos( 50,25 ) DermaPanel1:SetSize( 500, 500 ) DermaPanel1:SetTitle( "Items" ) DermaPanel1:SetVisible( true ) DermaPanel1:SetDraggable( true ) DermaPanel1:ShowCloseButton( true ) DermaPanel1:MakePopup() local DermaButton1 = vgui.Create( "DButton", DermaPanel1 ) DermaButton1:SetText( "Super Shorty" ) DermaButton1:SetPos( 12.5, 30 ) DermaButton1:SetSize( 100, 25 ) DermaButton1.DoClick = function() RunConsoleCommand("give", "weapon_supershorty") end local DermaButton2 = vgui.Create( "DButton", DermaPanel1 ) DermaButton2:SetText( "Baseball Bat" ) DermaButton2:SetPos( 125.5, 30 ) DermaButton2:SetSize( 100, 25 ) DermaButton2.DoClick = function() RunConsoleCommand( "give", "weapon_bat" ) end local DermaButton3 = vgui.Create( "DButton", DermaPanel1 ) DermaButton3:SetText( "test" ) DermaButton3:SetPos( 300, 30 ) DermaButton3:SetSize( 100, 25 ) DermaButton3.DoClick = function() RunConsoleCommand("give", "weapon_bugbait") end end function Hidemenu() if DermaPanel1:IsVisible() == true then DermaPanel1:SetVisible(false) end end concommand.Add("matsmenu", Playermenu) concommand.Add("+matsmenu", Playermenu) concommand.Add("-matsmenu", Hidemenu) [/lua]
I'm not sure why it wouldn't move with its parent but the position is relative to the parent. That's why it's outside the panel.
It wasn't parented properly. How it looked: [lua] local DermaButton3 = vgui.Create( "DButton", Dermapanel1 ) DermaButton3:SetText( "test" ) DermaButton3:SetPos( 300, 30 ) DermaButton3:SetSize( 100, 25 ) DermaButton3.DoClick = function() RunConsoleCommand("give", "weapon_bugbait") end [/lua] How it should look: [lua] local DermaButton3 = vgui.Create( "DButton", DermaPanel1 ) DermaButton3:SetText( "test" ) DermaButton3:SetPos( 300, 30 ) DermaButton3:SetSize( 100, 25 ) DermaButton3.DoClick = function() RunConsoleCommand("give", "weapon_bugbait") end [/lua] The "P" in DermaPanel1 was with small :)
Oh man, I need to start typing more carefully.
Sorry, you need to Log In to post a reply to this thread.