My stumbling block is around iupButtons which I can't find a solution for.
Any help would be much appreciated.
It fails on for intArgNum, strButton in ipairs(arg) do with "error attempt to index a nil value"
Function
Code: Select all
function iupButtons(strTitle,strMessage,strBoxType,...)
local intButton = 0 -- Returned value if X Close button is used
-- Create the GUI labels and buttons
local lblMessage = iup.label{title=strMessage,expand="YES"}
local lblLineSep = iup.label{separator="HORIZONTAL"}
local iupBox = iup.hbox{homogeneous="YES"}
if strBoxType == "V" then
iupBox = iup.vbox{homogeneous="YES"}
end
--THIS IS WHERE IT FAILS
for intArgNum, strButton in ipairs(arg) do
local btnName = iup.button{title=strButton,expand="YES",padding="4",
action=function() intButton=intArgNum return iup.CLOSE end}
iup.Append(iupBox,btnName)
end
-- Create dialogue and turn off resize, maximize, minimize, and menubox except Close button
local dialogue = iup.dialog{title=strTitle,iup.vbox{lblMessage,lblLineSep,iupBox},
dialogframe="YES",background="250 250 250",gap="8",margin="8x8"}
dialogue:show()
if (iup.MainLoopLevel()==0) then iup.MainLoop() end
dialogue:destroy()
return intButton
end -- function iupButtons
Usage
Code: Select all
--Call the function which will return a value of 1-6 for the button
intButton = iupButtons("Last updated..","Choose record types..","V","Individuals","Families","Sources","Notes", "Multimedia", "Cancel")
--Check the values and if not 'Cancel' set the value for strRecordType and the label for column 3 of the display
if intButton == 1 then strRecordType = "INDI" strRecordLabel = "Person" end
if intButton == 2 then strRecordType = "FAM" strRecordLabel = "Family" end
if intButton == 3 then strRecordType = "SOUR" strRecordLabel = "Source" end
if intButton == 4 then strRecordType = "NOTE" strRecordLabel = "Note" end
if intButton == 5 then strRecordType = "OBJE" strRecordLabel = "Multimedia" end
if intButton == 6 then return end --'Cancel' pressed so Exit the plugin