Hi ChaosInc,
Putting parentheses after the function name makes Lua call the function. If you want to assign the function itself to a variable, rather than its return values, you just write the function name. If it’s a method name, rather than a standalone function, then you usually have to write it as a string, in quotes, so you can look it up in the object table later.
This would work:
Code:
-- disable mouse stuffs
cb = CreateFrame( "CHECKBUTTON", "CFM_ClickButton", CFM_Panel1, "OptionsCheckButtonTemplate" )
cb:SetPoint( "LEFT", CFM_ClickText, "RIGHT", 0, 0)
cb:SetScale( 0.75 )
cb:SetScript( "OnClick", function( self )
if selName == nil or selName == "" then
return print( "Please select a frame first." )
else
CFM_ToggleSetting( self, "disableMouse" )
end
end )
-- code stuffs
function CFM_ToggleSetting( self, prop )
local frame = _G[ activeProfile[ selName ].frame ]
local func
-- determine what function will be needed based on passed property
if prop == "disableMouse" then
func = "EnableMouse"
end
if prop == "clamp" then
func = "SetClampedToScreen"
end
if self:GetChecked() == 1 then
activeProfile[ selName ][ prop ] = true
frame[ func ]( frame, true )
else
activeProfile[ selName ][ prop ] = false
frame[ func ]( frame, false )
end
end
But, it might be easier to just use the function name instead of some other string, like this:
Code:
CFM_ToggleSetting( self, "EnableMouse" )
function CFM_ToggleSetting( self, func )
local frame = _G[ activeProfile ][ selName ].frame
-- determine what function will be needed based on passed property
if self:GetChecked() == 1 then
activeProfile[ selName ][ func ] = true
frame[ func ]( frame, true )
else
activeProfile[ selName ][ func ] = false
frame[ func ]( frame, false )
end
end