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:SetSize(W, H)

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 as its client sided.
Next you will need to learn how to use Derma Properly
After this, to make a button use this, 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

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

[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.