Copied nearly exactly out of a wiki tutorial.
The frame becomes visible on the concommand but the slider outputs this error:
[B][autorun\client\derma.lua:24] attempt to index global 'NumSliderThingy' (a nil value)[/B]
[code]function frame_create() --Note that I changed the function name. You can change the function name to anything you want
frame = vgui.Create("DFrame")
frame:SetPos(50,50)
frame:SetSize(500,350)
frame:SetTitle("Testing Derma Controls")
frame:SetVisible(false) --This is important to set false or your frame will pop-up every time you join to server or a single player game.
frame:SetDraggable(true)
frame:ShowCloseButton(true)
frame:SetBackgroundBlur(false)
frame:MakePopup()
local NumSliderThingy = vgui.Create( "DNumSlider", frame_create )
NumSliderThingy:SetPos( 25,50 )
NumSliderThingy:SetSize( 150, 100 ) -- Keep the second number at 100
NumSliderThingy:SetText( "Max Props" )
NumSliderThingy:SetMin( 0 ) -- Minimum number of the slider
NumSliderThingy:SetMax( 256 ) -- Maximum number of the slider
NumSliderThingy:SetDecimals( 0 ) -- Sets a decimal. Zero means it's a whole number
NumSliderThingy:SetConVar( "sbox_maxprops" ) -- Set the convar
NumSliderThingy:SetVisible(false)
end
function frame_visible()
frame:SetVisible(true)
NumSliderThingy:SetVisible(true)
end
concommand.Add("+our_concommand",frame_visible)
hook.Add("Initialize","frame_create",frame_create)[/code]
NumSliderThingy is out of scope in the function fame_visible
[QUOTE=King Flawless;29107712]NumSliderThingy is out of scope in the function fame_visible[/QUOTE]
Please explain in greater detail!
Read this [url]http://www.lua.org/pil/4.2.html[/url]
[editline]11th April 2011[/editline]
Also anyone who can fix the code in the OP please don't post a fix he will learn a lot more reading the link I sent him and finding the problem him self.
[QUOTE=King Flawless;29108030]Read this [url]http://www.lua.org/pil/4.2.html[/url]
[editline]11th April 2011[/editline]
Also anyone who can fix the code in the OP please don't post a fix he will learn a lot more reading the link I sent him and finding the problem him self.[/QUOTE]
Thank you I now understand local and global variables!
I also fixed the problem!!
But like all coding I do another one has cropped up D:
The slider shows on command aswell as the frame but is not parented/does not follow where I drag the frame.
Picture added -
[URL=http://img857.imageshack.us/i/unled2i.png/][IMG]http://img857.imageshack.us/img857/671/unled2i.png[/IMG][/URL]
Yes the slider is parented to frame_create.
Because you are parenting it to frame_create not frame
[QUOTE=King Flawless;29125428]Because you are parenting it to frame_create not frame[/QUOTE]
/facepalm
Im an idiot.
Thank you a lot.
Sorry, you need to Log In to post a reply to this thread.