incrementing every 3 pictures

Advanced Renamer forum
#1 : 10/12-22 16:07
Richard Schneider
Posts: 2
Hey,
I have a folder of pictures with pictures (name is irrelevant), which I want to name as following:
S1_L1
S2_L1
S3_L1
S1_L2
S2_L2
S3_L2
S1_L3
...

I tried to script it like this:

var object_id;
var layer_number;
var i;

if ((index - 1) % 3 = 0) {
object_id = '1';
i = index + 2
} else {
if ((index - 2) % 3 = 0) {
object_id = '2';
i = index + 1
} else {
object_id = '3';
i = index
}
layer_number = Integer.toString(i);

return 'S' + object_id + '_L' + layer_number;
}

If include the last } i get the error 'invalid lvalue' if I exclude it, I get a parse-error. Where is my mistake?
Many thanks in advance!
Kindly,
Richard
#2 : 10/12-22 18:29
David Lee
Posts: 1125
You have several errors...

1) Advanced Renamer scripts are actually JavaScript functions called by the built-in script. The "{" and "}" are added automatically and are visible, greyed out, above and below the code window.
ie:

function (index, item) {
<Your Code>
}

2) The Java Script "if" statement can only contain one "else" clause. For intermediate conditions you need to use "else if":

if(...) {
...
} else if (...) {
...
} else if (...) {
...
} else {
...
}

3) Conditional equals is "==" not "=":

eg: if ((index - 1) % 3 == 0) { }

4) Your logic is faulty - and your solution is grossly over-complicated!

All you need is:

return 'S' + (index % 3 + 1) + '_L' + Math.ceil((index + 1) / 3);





edited: 10/12-22 22:40
#3 : 11/12-22 15:21
Richard Schneider
Posts: 2
Reply to #2:
Awesome, thank you so much!