Variables in formats

Any questions? Need some help?
Post Reply
Pator
Power User
Posts: 15
Joined: 04 Oct 2016, 07:29

Variables in formats

Post by Pator »

I have my movie format as

Movie/{myLang = any {language detection logic}}/...

This expands to Movies/English/...
And I can reuse myLang later on as needed.

What I have failed to achieve is to do variable assignments that do not expand/alter my format.

Ie.: I would like to create a boolean
isMyLanguage
If myLang matches /English|German|Spanish|Etc/

To use in
{isMyLanguage? Info.originaltitle : n} ({y})
Aso in {collection} which currently is always in English (due to locale I guess).
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Variables in formats

Post by rednoah »

1.
You can make boolean variables:

Code: Select all

{def myCondition = 'English' in ['English', 'German']; myCondition ? 'Y' : 'N'}
2.
Search for dynamic localization using the {localize} binding.

e.g.

Code: Select all

{localize[info.originalLanguage].collection}
:idea: Please read the FAQ and How to Request Help.
UKenGB
Posts: 49
Joined: 04 Jan 2017, 09:26

Re: Variables in formats

Post by UKenGB »

Regarding this subject, how is one supposed to define a variable in the format string?

I have {some code} that evaluates to what I want to use in 2 places. I have ascertained that a variable assignment appears to result in the value, so I could use such an assignment for the first instance (a folder name) and then just the variable for the filename in that folder. But I cannot figure out how to assign the above to a variable.

As I said {some code} gives me what I want, but {newVar = {some code}} or {def newVar = {some code}} both fail with a ScriptXXX$run_closure1@..... error.

So what is the correct way to define a variable?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Variables in formats

Post by rednoah »

The outermost {...} interpreted by FileBot have completely different semantics from anything in between which is interpreted by the Groovy engine. In Groovy, {...} may refer to code blocks or closures.

e.g.

Code: Select all

def x = 1; def y = x + x; y
:idea: Please read the FAQ and How to Request Help.
UKenGB
Posts: 49
Joined: 04 Jan 2017, 09:26

Re: Variables in formats

Post by UKenGB »

Yeah, got it 5 seconds after asking. Sorry.

I find posting a question is a sure fire way to ensure I then immediately figure it out for myself :-)

Thanks though.
mpegman
Posts: 19
Joined: 11 Feb 2023, 13:38

Re: Variables in formats

Post by mpegman »

how do you go outside {} with the variable range?

Code: Select all

{def myCondition = 'English' in ['English', 'German']; myCondition ? 'Y' : 'N'}
{ 
	myCondition // <--- this seems to have lost its value
}
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Variables in formats

Post by rednoah »

Each {...} is a separate Groovy script, and local variables only work within the same scope / same script. You can't have global variables.


e.g. you can use local variables like so:

Code: Select all

{ 
	def myCondition = 'English' in ['English', 'German']
	return myCondition
}
:idea: If you want complex custom code, then you can just write everything within a single {...} expression. That expression can be hundreds of lines if needed. It just so happen to be a single character for things like {n} but it's not limited to that.
:idea: Please read the FAQ and How to Request Help.
Post Reply