Derma Button ConVars?

Basically what i want it to know if its possible to SetConVars to buttons, if so how would you do this?

What i have so for is this, but i get errors. :rollout:



local Text = ""
local ConVar = ""

local function AddDermaButton(Parent, TextFont, ConVar, TextColor, Text, ButtonColor, W, H, X, Y)
	local DermaButton = vgui.Create("DButton", Parent)
	DermaButton:SetPos(X, Y)
	DermaButton:SetFont(TextFont)
	DermaButton:SetText(Text)
	DermaButton:SetSize(W, H)
	DermaButton:SetTextColor(TextColor)
	DermaButton:SetColor(ButtonColor)
	DermaButton:SetConVar(ConVar)
end


Note: I’m still new to LUA, so i might not know a’lot of things. So please don’t make fun of me. ;-;

Thank you for the help! :smile:


(User was banned for this post ("Wrong section. Go to the DEVELOPER DISCUSSION FOR DERMA help next time" - Kiwi))

I don’t know if you’re considered banned or not, if you can read this or not? But here I go…
Your going to need to use https://wiki.garrysmod.com/page/Category:net as its client sided.
Next you will need to learn how to use Derma Properly https://wiki.garrysmod.com/page/Derma_Basic_Guide.
After this, to make a button use this https://wiki.garrysmod.com/page/Category:DButton, obviously after you follow the other derma tutorial.

Finally you can set the convars, but obviously its going to be running on the client, if you wanted to changed convars use RunConsoleCommand, but using Panel:SetConVar will update the panel when a convar is changed or when you click the button it will update the convar as well.

Why was this person banned? This is the right section.

Anyway, SetConVar doesn’t work with DButtons because this would not make sense. If the user clicks a button, is the ConVar supposed to be true or false? There’s no way for the game to know what it’s supposed to set the ConVar to be.

If you’re confused, think of it like this - a DCheckBox works with SetConVar.
With a checkbox, it’s very clear whether or not the ConVar is enabled or disabled. A tick or no tick.

For a DButton, you are meant to use DoClick:



DermaButton.DoClick = function()
	RunConsoleCommand( "say", "Hi" ) -- makes the player say 'Hi' by running the 'say' command
end


This was copied from the first example on the DButton wiki page.

Also, your code should work fine. I don’t know why you got errors.
However, I do want to say that generally variables are lowercase without a capital letter at the start, but it doesn’t really matter.

  1. Console commands are shared so you don’t need to learn the net library.
  2. You don’t need to learn how to use derma properly either since you’re already doing fine.
  3. He’s already using a DButton.
  4. He’s already using SetConVar. Sadly, this does not work with DButtons.

Yeah I read it, but I didn’t know what angle he was coming at … server or client?

Another example on how to set a ConVar to something:



DermaButton.DoClick = function()
	RunConsoleCommand( "sv_cheats", "1" ) -- turns on cheats
end


[editline]17th August 2017[/editline]

You can’t run any derma functions at all on the server, so good point actually. Any errors you get are probably because the code is running on the server, or shared. Make sure it’s clientside only.