compiler does not see local function
Posted: 01 Sep 2022 20:25
simple selection code
if you have a file root, and at record selection window, you press cancel it will ask you if you want to use the file root
if you press Cancel Button on the do you want to use the file root screen, it returns cancel to the program
if you press Enter button it sets up global pointers.
both local functions are defined before line 83 inside the local function sltROOT
however, there is an error, and I do not understand why it is looking for a global function when there is a local function already defined.
debug gives:
83: attempt to call global 'choose_root' (a nil value)
if you have a file root, and at record selection window, you press cancel it will ask you if you want to use the file root
if you press Cancel Button on the do you want to use the file root screen, it returns cancel to the program
if you press Enter button it sets up global pointers.
both local functions are defined before line 83 inside the local function sltROOT
however, there is an error, and I do not understand why it is looking for a global function when there is a local function already defined.
debug gives:
83: attempt to call global 'choose_root' (a nil value)
Code: Select all
-- str sltROOT variables
local WS_CANCEL = false
local WS_Cancel = 'Cancel'
local WS_ENTER = true
local WS_OK = 'OK'
local _slt = {}
-- end sltROOT variables
-- select root
local function sltROOT()
_slt['_root'] = {fn_key = '', _YROOT = '', _YFATHER = '', _YMOTHER = '', _YFAM = ''}
local _root
local ptrFAM = fhNewItemPtr()
local lnkFAM = fhNewItemPtr()
local WS_RC
-- choose root. if cancel key is pressed and there is a file root, ask to use it.
local function mat_global_roots()
ptrFAM = fhGetItemPtr(_YROOT, '~.FAMC')
lnkFAM = fhGetValueAsLink(ptrFAM)
if ptrFAM:IsNotNull() then
local lnkHUSB = fhNewItemPtr()
local ptrHUSB = fhNewItemPtr()
lnkHUSB = fhGetItemPtr(lnkFAM, '~.HUSB[1]>')
ptrHUSB = fhGetItemPtr(lnkFAM, '~.HUSB[2]>')
local lnkWIFE = fhNewItemPtr()
local ptrWIFE = fhNewItemPtr()
lnkWIFE = fhGetItemPtr(lnkFAM, '~.WIFE[1]>')
ptrWIFE = fhGetItemPtr(lnkFAM, '~.WIFE[2]>')
-- same sex male
if lnkHUSB:IsNotNull() and ptrHUSB:IsNotNull() then lnkWIFE = ptrHUSB end
-- same sex female
if lnkWIFE:IsNotNull() and ptrWIFE:IsNotNull() then lnkHUSB = lnkWIFE lnkWIFE = ptrWIFE end
_YFATHER = lnkHUSB
_YMOTHER = lnkWIFE
_YFAM = lnkFAM
_slt['_root'].fn_key = WS_ENTER
_slt['_root']._YROOT = _YROOT
_slt['_root']._YFATHER = lnkHUSB
_slt['_root']._YMOTHER = lnkWIFE
_slt['_root']._YFAM = lnkFAM
end
end -- fn mat_global_roots
local function choose_root()
local txt
_YROOT = fhCallBuiltInFunction('FileRoot')
if _YROOT:IsNull()then
txt = 'File Root not set: Requires Root'
else
local fileroot = fhGetItemText(_YROOT, '~.NAME')
txt = ('Use File Root: %s'):format(fileroot)
end
WS_RC = fhMessageBox(txt, 'MB_OKCANCEL')
if WS_RC == WS_OK then
if _YROOT:IsNotNull()then
mat_global_roots()
else
WS_RC = sltROOT()
if WS_RC == WS_Cancel then
_slt['_root'].fn_key = WS_CANCEL
end
end
elseif WS_RC == WS_Cancel then
_slt['_root'].fn_key = WS_CANCEL
end
end
end -- fn choose_root
-- *ENTRY()
_root = fhPromptUserForRecordSel('INDI', 1)
if #_root == 0 then
choose_root()
if _slt['_root'].fn_key ~= WS_CANCEL then
_YROOT = _root[1]
mat_global_roots()
end
return _slt['_root']
end --fn sltROOT
local _root = sltROOT()
return