How to use if - else if - else properly?

Any questions? Need some help?
Post Reply
AleXSR700
Posts: 18
Joined: 27 May 2022, 21:44

How to use if - else if - else properly?

Post by AleXSR700 »

Hello everyone,
could someone help me figure out how to use if and else if/else properly with filebot?

I would like to have different formatting depending on the studio. But it seems I cannot just return the full expression.
I would like to have the year first, if the movie is part of a movie series.

Code: Select all

{
	if ('Marvel Studios' in info.productionCompanies) {
		return "./Marvel" /({y}) {n.replaceAll(/[?*:]/,'.').upperInitial()} {AudioLanguages} ({vf}.{vc}_{af}.{ac})
	} else if ('DC Entertainment in info.productionCompanies) { 
		return "." /({y}) {n.replaceAll(/[?*:]/,'.').upperInitial()} ({y}) {AudioLanguages} ({vf}.{vc}_{af}.{ac})
	} else {
		return "." /{n.replaceAll(/[?*:]/,'.').upperInitial()} ({y}) {AudioLanguages} ({vf}.{vc}_{af}.{ac})
	}
}
But it seems I cannot nest the entire syntax within the if statement. Is this generally not possible or is my syntax wrong somewhere?

Thank you :)
Alex
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to use if - else if - else properly?

Post by rednoah »

e.g.

Code: Select all

{
	if ('Marvel Studios' in info.productionCompanies) {
		return "./Marvel/($y) "
	} else if ('DC Films' in info.productionCompanies) { 
		return "./DC/($y) "
	} else {
		return "./"
	}
}

{ n.tr(/?*:/,'.').upperInitial() } {audioLanguages} ({vf}.{vc}_{af}.{ac})


:idea: Keep in mind that the outermost {...} delimit Groovy code, and then all the {...} inside are just Groovy code, so completely different in meaning:
viewtopic.php?t=1895


:idea: You can write your entire code in a single Groovy expression, but then you must take extra care for bits and pieces of your code that might throw an exception and thus break your intended program flow. Recommended only if you're familiar with the Groovy programming language.
:idea: Please read the FAQ and How to Request Help.
AleXSR700
Posts: 18
Joined: 27 May 2022, 21:44

Re: How to use if - else if - else properly?

Post by AleXSR700 »

You exmaple would not work because now the year is missing from normal movies.

I would always want the year as part of the title. But when it is a series of movies, the year should come first (thereby sorting the movies) whereas it should come after the title if it is a standalone movie.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to use if - else if - else properly?

Post by rednoah »

e.g.

Code: Select all

{
	if ('Marvel Studios' in info.productionCompanies) {
		return "./Marvel/($y) $n".tr(/?*:/,'.').upperInitial()
	} else if ('DC Films' in info.productionCompanies) { 
		return "./DC/($y) $n".tr(/?*:/,'.').upperInitial()
	} else {
		return "./$n ($y)".tr(/?*:/,'.').upperInitial()
	}
} {audioLanguages} ({vf}.{vc}_{af}.{ac})
:idea: Please read the FAQ and How to Request Help.
AleXSR700
Posts: 18
Joined: 27 May 2022, 21:44

Re: How to use if - else if - else properly?

Post by AleXSR700 »

Okay, that seems to work for everything except the "else" statement. The else statement is simply being ignored and the filename is then only audiolanguages etc.

Is the else statement for some reason not supported? All else if work fine. Just the final else is not working.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to use if - else if - else properly?

Post by rednoah »

Image

Looks good to me. The default sample Movie object correctly falls into the last else branch and injects "ELSE" into the target path.


:?: What movie are you testing with? What do you see? Please include screenshots so that I can see what you see.
:idea: Please read the FAQ and How to Request Help.
AleXSR700
Posts: 18
Joined: 27 May 2022, 21:44

Re: How to use if - else if - else properly?

Post by AleXSR700 »

It looks fine to me as well. But it is being ignored. Every single "else if" is working. The "else" is not.
Any other way of achieving this since "else" is not working?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to use if - else if - else properly?

Post by rednoah »

AleXSR700 wrote: 28 May 2022, 18:50 It looks fine to me as well. But it is being ignored. Every single "else if" is working. The "else" is not.
We both see a screenshot that shows if-then-else working perfectly and not being ignored. Yes? No? :lol:


AleXSR700 wrote: 28 May 2022, 18:50 Any other way of achieving this since "else" is not working?
Please take a screenshot of "else" not working, so that I can see what you're doing, find out what exactly isn't working, so that I can then suggest solutions or workarounds.
:idea: Please read the FAQ and How to Request Help.
AleXSR700
Posts: 18
Joined: 27 May 2022, 21:44

Re: How to use if - else if - else properly?

Post by AleXSR700 »

I am sorry, I found the culprit after trying to only return a simple "ELSE" without additional code.
I had added another field and it seemingly threw an error. You warned me about this and I tried to follow the instructions but seems I had a syntax error.

Working now *.*
Post Reply