Lua Script - how to iterate on a film images ?

Hi,
I’m trying to write some Lua script and have made some progress but I’m stuck here.
I would like to iterate on the images of a given film object and I don’t find the way.
The routine looks like (but doesn’t work):
image
I’ve checked the film (mfilm) holds the right id.
I’ve also seen this
image
but I’ve not found any related example.
I would appreciate any help :slight_smile:
Thanks

You are missing the end of the if clause.

1 Like

Yes, I did miss… :hushed:
Works far better. Thank you.

When the image is found, I get it properly.
When there is no image in the folder (parent folder) I get out the loop properly.
But when there is at least one image with no match I get this error:

LUA ERROR : incorrect index in database
stack traceback:
[C]: in ?
[C]: in ?
[C]: in metamethod ‘__index’
C:\Program Files\darktable\share\darktable\luarc:8: in for iterator ‘for iterator’
c:\Documents\Darktable/lua/mylua/test.lua:29: in upvalue ‘getmasterimage’
c:\Documents\Darktable/lua/mylua/test.lua:54: in function <c:\Documents\Darktable/lua/mylua/test.lua:37>
[C]: in ?
[C]: in ?

:confused:

EDIT:Using the number of images in the film (#mfilm) I limit the number of iterations and exit the loop before getting the error. That makes it. :disappointed_relieved:

I noticed the same when trying earlier. It seems that there is some garbage in the list. Or something like that. I have no idea to be honest.