Derma not displaying with concommand.Add

I’m trying to teach myself Lua and I tried to create a test Derma script and it won’t seem to work with console commands. I’m not sure how I’m supposed to fix an error such as this:


[lua\dermaclosebutton.lua:22] attempt to index global 'frame' (a nil value)


Here’s the function I used on line 22


function displayOn()
	frame:SetVisible(true)
end

frame is not defined.
It would be something like…
[lua]
local frame = vgui.Create("")
[/lua]

It’s already defined. Here’s the first two lines of the Lua.


function create_frame()
	local frame = vgui.Create("DFrame")


Yes, well, your creating the variable frame inside the function create_frame() which means the variable is only available inside that function.
Move local frame above function create_frame()
and change
local frame = vgui.Create(“DFrame”)
to
frame = vgui.Create(“DFrame”)

google variable scope and read about that.

That did the trick! Thanks!