Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using startAsyncTask and getting a return value

New Here ,
Mar 25, 2012 Mar 25, 2012

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.

TOPICS
SDK
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 25, 2012 Mar 25, 2012

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

Translate
LEGEND ,
Mar 25, 2012 Mar 25, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2012 Mar 25, 2012

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2012 Mar 25, 2012
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines