• Action with a button doesn't work
    9 replies, posted
Hi everyone, Today, I would like to make a button which is able to be enabled only if the checkbox have been checked before. This is my code (it not working): local checkcl = vgui.Create( "DCheckBoxLabel", Panel ) checkcl:SetPos( 25, 265 ) checkcl:SetText( "I confirm that I am over 16 years of age" ) checkcl:SizeToContents() function checkcl:GetChecked( var ) if ( IsValid(var)) then Button:SetEnabled( true ) else Button:SetEnabled( false ) end end local Button = vgui.Create( "DButton" , Panel) Button:SetPos(250, 295) Button:SetSize( 100, 50 ) Button:SetText( "Validate" ) Button.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, 0, 0, Color( 0, 0, 153, 250 ) ) end Button.DoClick = function( ) Panel:Close() end Thanks.
-- [editline]17th February 2017[/editline] It work! [CODE]local Panel = vgui.Create( "DFrame" ) Panel:SetPos( 100, 100 ) Panel:SetSize( 300, 200 ) Panel:SetTitle( "My new Derma frame" ) Panel:SetDraggable( true ) Panel:MakePopup() local checkcl = vgui.Create( "DCheckBoxLabel", Panel ) checkcl:SetPos( 25, 10 ) checkcl:SetText( "I confirm that I am over 16 years of age" ) checkcl:SizeToContents() local Button = vgui.Create( "DButton" , Panel) Button:SetPos(250, 60) Button:SetSize( 100, 50 ) Button:SetText( "Validate" ) Button.DoClick = function( ) end function checkcl:Think() if checkcl:GetChecked() == true then Button:SetEnabled( true ) else Button:SetEnabled( false ) end end[/CODE]
Thanks Heroezzz, you save me. But can you explain me why you use Think(), and what it mean ? Thanks.
[QUOTE=Ralxys;51836169]Thanks Heroezzz, you save me. But can you explain me why you use Think(), and what it mean ? Thanks.[/QUOTE] Just [CODE]function checkcl:GetChecked( var )[/CODE] function takes only [U]true[/U] and [U]false[/U] and can not be used as a variable! because it only takes labor and Fals and could not be used for functions аA function to think speaks for itself! She thinks! Just read it [URL="https://wiki.garrysmod.com/page/DCheckBox/GetChecked"]GetChecked[/URL] and [URL="https://wiki.garrysmod.com/page/PANEL/Think"]Think[/URL] [editline]17th February 2017[/editline] [QUOTE=Ralxys;51836169]Thanks Heroezzz, you save me. But can you explain me why you use Think(), and what it mean ? Thanks.[/QUOTE] If you have any problems, please contact me!
Pretty hard to understand because I'm beginner. But I will continue in aim to better understand. [editline]17th February 2017[/editline] If I understood correctly, you will mean that the thing that I want to do need to have Think because this function have a choice True or False. But is the function can work without Think ?
[QUOTE=Ralxys;51836314]Pretty hard to understand because I'm beginner. But I will continue in aim to better understand. [editline]17th February 2017[/editline] If I understood correctly, you will mean that the thing that I want to do need to have Think because this function have a choice True or False. But is the function can work without Think ?[/QUOTE] The function is often used to think, but you need to know what features are valid values ​​if, else, else if
Hi sorry, But i've an another question just to know how can i import a custom picture in game which is button after? I've seen how can i make a button with picture but i don't know where i put the pictures. Cordially
[QUOTE=Ralxys;51836793]Hi sorry, But i've an another question just to know how can i import a custom picture in game which is button after? I've seen how can i make a button with picture but i don't know where i put the pictures. Cordially[/QUOTE] [CODE]local DermaBtn = vgui.Create( "DButton",DermaPanel ) DermaBtn:SetPos( DermaPanel:GetTall() + 70 , 10 ) DermaBtn:SetSize( 20, 20 ) DermaBtn:SetText( "" ) function DermaBtn:Paint(w,h) surface.SetDrawColor(Color(255,255,255)) surface.SetMaterial( Material("icon16/cancel.png" )) surface.DrawTexturedRect(0,0,16,16) end DermaBtn.DoClick = function() DermaPanel:Close() end[/CODE] [URL=http://pixs.ru/showimage/3jpg_8259385_25211382.jpg][IMG]http://i12.pixs.ru/storage/3/8/2/3jpg_8259385_25211382.jpg[/IMG][/URL] Example 2 [CODE]local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 450, 200 ) DermaPanel:SetSize( 400, 300 ) DermaPanel:SetTitle( "My new Derma frame" ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton(false) DermaPanel:MakePopup() local fka = vgui.Create("DImage", DermaPanel) fka:SetImage("backgrounds/caste_nostalgia.jpg") fka:SetPos(0, 0) fka:SetSize(ScrW(), ScrH())[/CODE] [URL=http://pixs.ru/showimage/4jpg_1719120_25211401.jpg][IMG]http://i12.pixs.ru/storage/4/0/1/4jpg_1719120_25211401.jpg[/IMG][/URL] [CODE] local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 450, 200 ) DermaPanel:SetSize( 400, 300 ) DermaPanel:SetTitle( "My new Derma frame" ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton(false) DermaPanel:MakePopup() function DermaPanel:Paint(w,h) draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 115 ) ) surface.SetDrawColor(Color(255,255,255)) -- Color img surface.SetMaterial( Material("icon16/user.png" )) surface.DrawTexturedRect(20,20,16,16) -- (x pos,y pos,size x,size y) end[/CODE] [URL=http://pixs.ru/showimage/5jpg_8305374_25211421.jpg][IMG]http://i12.pixs.ru/storage/4/2/1/5jpg_8305374_25211421.jpg[/IMG][/URL]
Ok, I understand but where is the directory for images ? Cordially.
[QUOTE=Ralxys;51839978]Ok, I understand but where is the directory for images ? Cordially.[/QUOTE] You can yourself upload in: C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\download\materials
Sorry, you need to Log In to post a reply to this thread.