Math functions and Scripting?

Tags: #<Tag:0x00007f7d06e3e3d0>

I see the mathematical functions for naming script creation. Let’s say I get a numerical value from a tag or variable, can I use that value mathematically in scripting outcomes?

$if($gte($add(%_value1%,%_value2%),%_value3%),$set(_this,%_value4% … etc.

$set(_someNumber,%_bitrate%)

In and If/Then/Else flow:

If %_someNumber% is dividable by 8? (Any whole number value returned means yes.)

Yes? (Then) …
No? (Else) …

$if($eq($div(%_bitRateValue%,8),$set(_thiS,That)),$set(_thiS,Them))

Or can the returned numerical value of $mul(8,8) be $set() to as another variable, and then used in another tabulation for if/then/else gt, lt, gte, lte, etc…

No? Well, too bad.

I think the root of the question is can I get a result from one of these functions and use it in another of them to figure something out?

$add, $sub, $div, $mul - and detect if the returned value is a whole number or has a decimal remainder?

1 Like

Of course you can, just like the result of any other function.

All the available mathematical functions return integers, so this will obviously not work correctly. You can, however, easily write your own scripting functions to work around that.

2 Likes

The $mul(x,y,args) (arguments) kinda throws me, so basically that is the “if,then,else” being a required argument for the function. I can do as little as $set the value returned to _variable and further work with it, or whatever else in that space.

Where I’m having issues is getting the actual result.

$mul(12,12$,set(_theResult ... where do I find the 144 that it should be?)
$mul(12,12$,%_theResult% Of course this shouldn’t work, but just making sure.

Try this:

$set(_theResult,$mul(12,12))

or this:

$set(_theResult,$mul(12,6,2))
1 Like

Well … Well … Well …

Okay then, the scripting docs show: $mul(x,y,*args)`

What is not implied is that computation itself needs to be -IN- the $set(,) - You’re not getting the value out of it. You’re telling something that the value = the _theResult of this math.

Which apparently is how $left(,) . .$right… work too. That was totally not even evident to me based on reading that scripting documentation.

…and finding example scripts here is a bit amusing with the search … As it ignores the $, or most likely it means something else to the search input.

So searching for $left … $left(, etc. gives you anything where someone uses the word ‘left’ also, and so did ‘$left’ … so I just tried “$left” and viola! :boom:

There’s several hours I’m not going to get back, :rage: however they’re not totally wasted. I’m sure -NOT- going to forget how that syntax needs to be structured now. :scream:

S’all good…

Thanks for the whack with the Clue-by-4… !!

I better stay away from Florida, as I’m likely not to realize that really is an alligator … and about to eat me.

Maybe there are some outdated or wrong docs somewhere, but the official documentation on https://picard.musicbrainz.org/docs/scripting/#functions says:

$mul(x,y,*args)

    Multiplies x by y.
    Can be used with an arbitrary number of arguments.
    i.e. $mul(x,y,z) = ((x * y) * z)

Substituting your previous example would not work:

$mul(12,12,$set(_theResult))
12 * 12 * $set(_theResult)

The documentation for those is even more clear on how they work, it explicitly states that they return the result:

$left(text,num)

    Returns the first num characters from text.

$right(text,num)

    Returns the last num characters from text.

The documentation on Picards website helps you there: https://picard.musicbrainz.org/docs/scripting/#tagger_script_examples :slight_smile:

3 Likes