How do you create ConVars and Tool tab options in Gmod?

Hi, I’m a complete noob and have no idea what I’m doing…
Please help :s:

Anyway, so I want to create some settings for a little project I’m making for myself. Long story in short, I have no idea how to. I’ve scoured the Gmod wiki for help, no luck.
What I want to do, is put some settings in the options tab (sliders, checkboxes etc.).
Now I have some configs that maybe I could use to create some ConVars that I can use for the settings tab. (Excuse me if anything I say is rubbish, I honestly have no idea what I’m talking about).

Here’s the config stuff


TerminalR.Config = {}

TerminalR.Config.CleanUpSave = true
TerminalR.Config.PermaSave = true
TerminalR.Config.HackTime = 25
TerminalR.Config.HackProtectionTime = 60
TerminalR.Config.HackErrorLimit = 5
TerminalR.Config.HackScoreNeed = 35

This is as far as I could get (It doesn’t work)


TerminalR.Config.CleanUpSave = CreateClientConvar("terminalr_cleanupsave", "1", true, false)
TerminalR.Config.PermaSave = CreateClientConvar("terminalr_permasave", "1", true, false)
TerminalR.Config.HackTime = CreateClientConvar("terminalr_hacktime", "25", true, false)
TerminalR.Config.HackProtectionTime = CreateClientConvar("terminalr_hackprotectiontime", "60", true, false)
TerminalR.Config.HackErrorLimit = CreateClientConvar("terminalr_hackerrorlimit", "5", true, false)
TerminalR.Config.HackScoreNeed = CreateClientConvar("terminalr_hackscoreneed", "35", true, false)

That’s it! If someone could point me in the right direction, that’d be appreciated.

Duck

The convars would work if you had a capital V on Var (CreateClientConVar).

CreateClientConVar

If you want to add some options to the menu, I usually do this in a clientside autorun file:



hook.Add( "PopulateToolMenu", "ADDON NAME Settings", function()
	spawnmenu.AddToolMenuOption( "Options", "SOME CATEGORY", "INTERNAL CLASS NAME", "DISPLAYED CLASS NAME", "", "", function( panel )
		panel:ClearControls()
		-- Add stuff here
	end )
end )


To add more stuff to the menu, it uses the same structure as the DForm, so all these work:

DForm:AddItem

DForm:Button

DForm:CheckBox

DForm:ComboBox

DForm:ControlHelp

DForm:Help

DForm:ListBox

DForm:NumberWang

DForm:NumSlider

DForm:PanelSelect

DForm:TextEntry

Just for fun, here’s an example:



CreateClientConVar( "cool_convar", "0", true, false )
CreateClientConVar( "sick_convar", "123", true, false )
CreateClientConVar( "epic_convar", "sample text", true, false )

hook.Add( "PopulateToolMenu", "AddonSettings", function()
	spawnmenu.AddToolMenuOption( "Options", "Quality Addons", "Sick_Addon_Options", "SICK ADDON OPTIONS", "", "", function( panel )
		panel:ClearControls()
		panel:CheckBox( "Look at this sexy check box", "cool_convar" )
		panel:NumSlider( "Check out this hot slider", "sick_convar", 0, 1000 )
		panel:TextEntry( "You get the idea", "epic_convar" )
	end )
end )


In the menu:

https://i.imgur.com/dvR4jWl.png[/t]

Pressing C:
[t]https://i.imgur.com/7Pc0LOJ.png

Thanks for the reply mate!

EDIT:
Just tried it out, isn’t working.

So I chucked this at the end of the autorun lua file:


TerminalR.Config.CleanUpSave = CreateClientConVar("terminalr_cleanupsave", "1", true, false)
TerminalR.Config.PermaSave = CreateClientConVar("terminalr_permasave", "1", true, false)
TerminalR.Config.HackTime = CreateClientConVar("terminalr_hacktime", "25", true, false)
TerminalR.Config.HackProtectionTime = CreateClientConVar("terminalr_hackprotectiontime", "60", true, false)
TerminalR.Config.HackErrorLimit = CreateClientConVar("terminalr_hackerrorlimit", "5", true, false)
TerminalR.Config.HackScoreNeed = CreateClientConVar("terminalr_hackscoreneed", "35", true, false)

hook.Add( "PopulateToolMenu", "TerminalRSettings", function()
	spawnmenu.AddToolMenuOption( "Options", "Terminal Mod Rebooted", "trm_settings", "Settings", "", "", function( panel )
		panel:ClearControls()
		panel:CheckBox( "Clean-Up Save", "terminalr_cleanupsave" ) 
		panel:CheckBox( "Perma-Save", "terminalr_permasave" )
		panel:NumSlider( "Hacking Time Restraint" "terminalr_hacktime", 20, 100 )
		panel:NumSlider( "Firewall Activation Time", "terminalr_hackprotectiontime", 30, 100 )
		panel:NumSlider( "Hacking Error Limit", "terminalr_hackerrorlimit", 5, 100 )
		panel:NumSlider( "Hacking Score Desideratum", "terminalr_hackscoreneed", 5, 100 )
	end )
end )

The category isn’t showing up in the spawnmenu, and it still hasn’t created any convars.
I’m not getting any script errors either.

Have I done something wrong?
Little help please :s:

Thanks,
Duck