I'm making a tool that allows you to configure your speed with a slider and I don't know how to output it. The tool does nothing. It only has the slider and I need it to output the value of the slider. How would I do this? Thanks in advance!
[CODE]
--[[
Made by Metamorphics
( STEAM_0:1:52851671 is the one and only author)
]]--
AddCSLuaFile()
TOOL.Category = "DC Powers Pack"
TOOL.Name = "Speedster Configuration"
TOOL.Command = nil
TOOL.ConfigName = ""
function TOOL:LeftClick( trace )
end
function TOOL:RightClick( trace )
end
function TOOL.BuildCPanel( panel )
panel:AddControl("Slider", {
Label = "Speed",
Type = "Float",
Min = "500",
Max = "9000",
})
end
[/CODE]
AddControl is deprecated ( [url]https://wiki.garrysmod.com/page/ControlPanel/AddControl[/url] ).
Try using a NumSlider instead ([url]https://wiki.garrysmod.com/page/DForm/NumSlider[/url])
It allows a convar to be changed. Perhaps you could create your own?
Try this:
[CODE]
function TOOL.BuildCPanel( panel )
local slider = vgui.Create( "DNumSlider" )
slider:SetText( "Speed" )
slider:SetMin( 500 )
slider:SetMax( 9000 )
function slider:OnValueChanged( val ) -- called when the slider's value is changed
print( val ) -- print it (for example)
end
panel:AddItem( slider )
end
[/CODE]
[QUOTE=MPan1;50229440]Try this:
[CODE]
function TOOL.BuildCPanel( panel )
local slider = vgui.Create( "DNumSlider" )
slider:SetText( "Speed" )
slider:SetMin( 500 )
slider:SetMax( 9000 )
function slider:OnValueChanged( val ) -- called when the slider's value is changed
print( val ) -- print it (for example)
end
panel:AddItem( slider )
end
[/CODE][/QUOTE]
I got the slider to work just fine with addcontrol? Why can't I use it?
[QUOTE=Metamorphics;50231398]I got the slider to work just fine with addcontrol? Why can't I use it?[/QUOTE]
Because I don't think there's a way to modify the actual slider it adds since that function doesn't seem to return anything
[editline]30th April 2016[/editline]
I just thought since you wanted to output the slider's value, you need to be able to actually access the slider's metatable
Sorry, you need to Log In to post a reply to this thread.