Page 1 of 1
How to locate missing census facts in a plugin
Posted: 24 May 2016 16:53
by Gowermick
I am new to plugin coding, but progressing well, and have been able to go through the records, and Identify each individual who was alive at each census.
I now need to check if they already have a census fact for a specific year.
This is achieved this in a query by including the row item, Exclude if =Exists(%INDI.CENS[year=1841]%)
How do I reproduce this in a plugin?
With possibly none or more census facts for each individual, how do I check if one of them is for 1841?
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 17:00
by tatewise
I presume you have been able to retrieve ~.BIRT and ~.DEAT facts for each INDI.
So use similar technique to retrieve ~.CENS[year=1841] and if the returned pointer is Null then no Census Event exists for 1841, and this is an INDI whose To Do Fact needs updating.
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 17:11
by Gowermick
Mike,
Thanks for that, I must have been doing something wrong, as I didn't realise the phrase [year=1841] was still a valid expression, as it didn't seem to work!
I'll give it another try!
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 18:00
by tatewise
Assuming you have
ptrIndi pointing to Individual record then the following works:
Code: Select all
local ptrCens = fhGetItemPtr(ptrIndi,"~.CENS[year=1841]")
if ptrCens:IsNull() then
end
You can even set a variable for the year itself and obtain that from the user:
Code: Select all
local strYear = "1841"
local ptrCens = fhGetItemPtr(ptrIndi,"~.CENS[year="..strYear.."]")
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 18:11
by Gowermick
Mike,
Once again many thanks.
I do feel the documentation on plugins is somewhat lacking.
for example why the '..' in the expression [census=..stryear..]?
Haven't come across these in the documentation, except for string concatenation!
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 18:26
by tatewise
Well, you are correct, it is string concatenation!
"~.CENS[year=" plus
strYear plus
"]" becomes
"~.CENS[year=1841]" if
strYear contains
"1841" i.e. two literal strings and a string variable concatenated together.
You need to supplement the specific
FH API documentation with the general
Lua documention especially
http://www.lua.org/manual/5.1/ mentioned in several places. Much of the code in a Plugin is general
Lua so only the
FH API is provided by FH help pages.
In plugins:getting_started|> Getting Started Writing Plugins the very first sentence says "
Plugins are written in Lua (currently release 5.1)," and that blue link takes you to the manual.
It is also in the FH help page
Introduction to Lua near the bottom, and in the Plugin editor window it is under
Help > Lua Online Reference Manual.
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 18:55
by Gowermick
Reminds me of programming msAccess, with SQL statements, putting variables inside quotes using concatenation just like LUA
Only trouble is, it doesn't makes reading code easy, nor debugging!
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 19:03
by tatewise
I suspect you have misunderstood string concatenation, because variables will never be inside quotes, otherwise they are no longer variables.
Take "~.CENS[year=" .. strYear .. "]" for example.
"~.CENS[year=" is one quoted literal string
strYear is a variable (not inside quotes) and may be assigned any literal string
"]" is another quoted literal string
c.f.
"strYear" is a quoted literal string, not a variable
All three are joined together to form one long string.
Think of the .. operator for strings as similar to the + operator for numbers.
Re: How to locate missing census facts in a plugin
Posted: 24 May 2016 20:22
by Gowermick
Mike,
Not the case at all, it is just a case of being unfamilar with LUA, not recognising what is inside quotes and what is outside. As I already said, doesn't make for easy reading of code.