Copy link to clipboard
Copied
Hello,
I'm just starting to try and learn LUA and the whole Lightroom SDK. Here is a sample of my code:
local lrApplication = import 'LrApplication'
local LrTasks = import 'LrTasks'
local activeCatalog = lrApplication.activeCatalog()
local currentPhotos = activeCatalog:getMultipleSelectedOrAllPhotos()
local y = LrTasks.startAsyncTask(function() return currentPhotos[1]:getFormattedMetadata('fileName') end)
wheneven I check or try to use y it is nil.
Please someone tell me the stupid thing I'm doing wrong so I don't lose any more of my dwindling hair.
I know that currentPhotos has 5 photos in it's collections because later on I do this:
for i, onePhoto in ipairs(currentPhotos) do
and it loops through 5 times, which matches up to the number of photos in the folder I have selected in Lightroom.
Thanks.
1 Correct answer
start-async-task doesn't return a value, it just schedules a task and keeps on going - the task runs later.
In general, it's best to start a task immediately in response to a button press or menu selection..., and do everything within that task. - then you don't have to start them anywhere else, unless you need them as true parallel processes, like background tasks.
To keep multiple tasks from starting due to asyncronous events, use some form of recursion guarding.
Rob
Copy link to clipboard
Copied
start-async-task doesn't return a value, it just schedules a task and keeps on going - the task runs later.
In general, it's best to start a task immediately in response to a button press or menu selection..., and do everything within that task. - then you don't have to start them anywhere else, unless you need them as true parallel processes, like background tasks.
To keep multiple tasks from starting due to asyncronous events, use some form of recursion guarding.
Rob
Copy link to clipboard
Copied
Click (sound of light bulb turning on)
Thank you Rob. That got me over that learning curve and expanded my possibilities. Now I'm able to loop through the files and get what I want. I had to expand the startAsyncTask to cover more of my code for it to work they way I expected.
Copy link to clipboard
Copied
Yep.
Note, consider post-async-task-with-context, instead of start-async-task.
The difference is that you can use the context to define error handling, so errors that occur aren't deep 6'd when it's in response to button press, as example.
More info and elare plugin framework here: https://www.assembla.com/spaces/lrdevplugin/
PS - source code there is out of date - http://www.robcole.com/Rob/ContactMe for fresh stuff.

