Problem with Panel:Think

Hi all i have a little problem with this code:


//prova.lua
local TestConvar = CreateClientConVar( "test_enabled", 0, true, false )
local function prova(Panel)
	Panel:ClearControls()
	Panel:AddControl("Label", {Text = "Some text"})
	Panel:AddControl("Label", {Text = ""})
	Panel:AddControl("Slider", { Label = "Prova:", Max = 2, Command = "test_enabled" } )
end
function AddPopulateToolMenu()
	spawnmenu.AddToolMenuOption("prova", "prova", "", "#prova", "", "", prova)
end

hook.Add("PopulateToolMenu", "AddPopulateToolMenu", AddPopulateToolMenu)

function prova:Think()
print( "test_enabled " ..GetConVar( "test_enabled" ):GetInt())
end


The error is:


[ERROR] addons/prova/lua/autorun/prova.lua:25: attempt to index global 'prova' (a function value)
  1. unknown - addons/prova/lua/autorun/prova.lua:25

Where am i wrong ?

local function prova(Panel)

Thx but same error :frowning:

EDIT
I found a workaround to solve it, but i think it is resources wasteful.


//prova.lua
if (SERVER) then
	AddCSLuaFile ("prova.lua")
	return
end

if (CLIENT) then

	local TestConvar = CreateClientConVar( "test_enabled", 0, true, false ) 

	local function prova(Panel)
		Panel:ClearControls()

		Panel:AddControl("Label", {Text = "Some text"})
	
		Panel:AddControl("Label", {Text = ""})

		Panel:AddControl("Slider", { Label = "Prova:", Max = 2, Command = "test_enabled" } )

	end

	function AddPopulateToolMenu()

		spawnmenu.AddToolMenuOption("prova", "prova", "", "#prova", "", "", prova)

	end



	hook.Add("PopulateToolMenu", "AddPopulateToolMenu", AddPopulateToolMenu)



	local function printer()
		print( "test_enabled " ..GetConVar( "test_enabled" ):GetInt())

	end
	hook.Add( "OnSpawnMenuClose", "printer", printer)
end