* How to locate missing census facts in a plugin

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
avatar
Gowermick
Megastar
Posts: 1629
Joined: 13 Oct 2015 07:22
Family Historian: V7
Location: Swansea

How to locate missing census facts in a plugin

Post by Gowermick » 24 May 2016 16:53

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?
Mike Loney

Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: How to locate missing census facts in a plugin

Post by tatewise » 24 May 2016 17:00

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
Gowermick
Megastar
Posts: 1629
Joined: 13 Oct 2015 07:22
Family Historian: V7
Location: Swansea

Re: How to locate missing census facts in a plugin

Post by Gowermick » 24 May 2016 17:11

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!
Mike Loney

Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: How to locate missing census facts in a plugin

Post by tatewise » 24 May 2016 18:00

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.."]")
 
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
Gowermick
Megastar
Posts: 1629
Joined: 13 Oct 2015 07:22
Family Historian: V7
Location: Swansea

Re: How to locate missing census facts in a plugin

Post by Gowermick » 24 May 2016 18:11

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!
Mike Loney

Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: How to locate missing census facts in a plugin

Post by tatewise » 24 May 2016 18:26

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
Gowermick
Megastar
Posts: 1629
Joined: 13 Oct 2015 07:22
Family Historian: V7
Location: Swansea

Re: How to locate missing census facts in a plugin

Post by Gowermick » 24 May 2016 18:55

Reminds me of programming msAccess, with SQL statements, putting variables inside quotes using concatenation just like LUA :lol:
Only trouble is, it doesn't makes reading code easy, nor debugging!
Mike Loney

Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: How to locate missing census facts in a plugin

Post by tatewise » 24 May 2016 19:03

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
Gowermick
Megastar
Posts: 1629
Joined: 13 Oct 2015 07:22
Family Historian: V7
Location: Swansea

Re: How to locate missing census facts in a plugin

Post by Gowermick » 24 May 2016 20:22

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.
Mike Loney

Website http://www.loney.tribalpages.com
http://www.mickloney.tribalpages.com

Post Reply