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).
Variables in formats
Re: Variables in formats
1.
You can make boolean variables:
2.
Search for dynamic localization using the {localize} binding.
e.g.
You can make boolean variables:
Code: Select all
{def myCondition = 'English' in ['English', 'German']; myCondition ? 'Y' : 'N'}
Search for dynamic localization using the {localize} binding.
e.g.
Code: Select all
{localize[info.originalLanguage].collection}
Re: Variables in formats
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?
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?
Re: Variables in formats
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.
e.g.
Code: Select all
def x = 1; def y = x + x; y
Re: Variables in formats
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.
I find posting a question is a sure fire way to ensure I then immediately figure it out for myself

Thanks though.
Re: Variables in formats
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
}
Re: Variables in formats
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:
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.
e.g. you can use local variables like so:
Code: Select all
{
def myCondition = 'English' in ['English', 'German']
return myCondition
}
