I would be easier to answer that question if you posted the whole script. The actaul error message with line number would be good to know as well.
At a guess, this line is probably the problem :
if (autoshdn > 0 and picturecount > 5 and get_day_seconds-lastpicturesec > autoshdnsec) then shutdown() end
as it's the only thing in your code doing arithmetic.
I'd suggest changing it to :
if (autoshdn > 0 and picturecount > 5 and get_day_seconds()-lastpicturesec > autoshdnsec) then shutdown() end
as the get_day_seconds()-lastpicturesec > autoshdnsec part is not evaluated until after the sixth picture is taken.