# Use of Varibles in Export Scripts

**URL:** https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481
**Category:** Export
**Created:** [December 2, 2016, 6:53pm UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481 "2016-12-02T18:53:16Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pdwhite](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@pdwhite](https://community.mp3tag.de/u/pdwhite)
#### Post date: [December 2, 2016, 6:53pm UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481/1 "2016-12-02T18:53:16Z")

</div>

I am attempting to create an export script that uses variables to sum up %length% values as each %track% loop occurs. I am converting the current length to seconds as a $num(x,n) succesfully, and placing it in a variable. However I still can't find a way to add the next track's %length% value to it. $add doesn't appear to work on user variables, and there is no real documentation on variables and how they can be used.

If anyone has notes on variable use or could reply with the proper script syntax to do the things below, I would be very grateful.

Generally, Variable1 loaded using $put(SLEN,($num(%\_length\_seconds%,5))), using Variable2 as the running total, by adding %\_length\_seconds% or Variable1 with the running sum of the loops.

%add() used with or without $num does not appear to work.

I could probably use %\_total\_time\_seconds% without modifiacation, but it actually _decrements_ total time by %\_length\_seconds% on each pass through the loop, which is the opposite of I would expect.

One more confusing area: If I load a variable using $put(SLEN,($num(%\_length\_seconds%,5))), which results in a $get value shown as "(nnnnn)", whereas using %\_total\_time% displays nn:nn:nn.

More confusing is $num(%\_total\_time\_seconds%,5) which yields 000000

I understand that this is all _'very electric and dangerous,'_ but if you have a reference or can show an example, it would be much appreciated. ![:rolleyes:](https://community.mp3tag.de/uploads/default/original/1X/3a79e8b0b7d169b30216785521d7c6f4f895c421.gif ":rolleyes:")

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 3, 2016, 10:59am UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481/2 "2016-12-03T10:59:02Z")

</div>

> [@PDWhite](#):
>
> I am attempting to create an export script that uses variables to sum up %length% values ...

For examples see there ...  
[/t/10145/1](https://community.mp3tag.de/t/10145/1)  
[Gesamtlänge eines Ordner in Verzeichnis integrieren](https://community.mp3tag.de/t/9470/6)  
[/t/12016/1](https://community.mp3tag.de/t/12016/1)

DD.20161203.1300.CET

---

<div class="post-metadata">

### Author: ![pdwhite](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@pdwhite](https://community.mp3tag.de/u/pdwhite)
#### Post date: [December 3, 2016, 5:51pm UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481/3 "2016-12-03T17:51:48Z")

</div>

Thank you for your reply.

Before adding this thread to the forum, I had searched and found the links referenced in your reply. Unfortunately that is not what I've set out to do.

It is not my purpose to find the total playing time of my listed files, but rather to crate a running total.

I.E., Tune #1 length is 90 seconds, Running total is 90 seconds.

```
   Tune #2 length is 208 seconds. Running total is 298 seconds.
   Tune #3 length is 104 seconds. Running total is 402 seconds, etc.

```

I am trying to add the length of the current tune in the loop to the time total of the _preceding_ tunes.

The running total will only show the full running time when the entire loop is completed.

I tried adding $num(%\_length\_seconds%,5), to a variable named RTTL, which was created by $put(RTTL,($num(%\_length\_seconds%,5)) on the first time through the loop.

So far, I have been unable to add a number to an existing (numeric) variable. I can $add two 'numbers' and $put them to a variable, but not add a number to _value_ of a numeric variable.

Since the $get(RTTL) value from the first pass returns the contents in parentheses, I am assuming that it is numeric and that I can use it as a number and add its value in a $add statement. But it just won't work.

There does not appear to be any explicit functionality for _casting_ a user variable to string or a string to numeric.

If there is any syntactical manipulation that makes it possible to add a numeric value to the value of an existing user variable or put the sum into a second user variable, I would like to know it.

Thank you. 🙂

---

<div class="post-metadata">

### Author: ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)
#### Post date: [December 3, 2016, 7:48pm UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481/4 "2016-12-03T19:48:06Z")

</div>

> [@PDWhite](#):
>
> It is not my purpose to find the total playing time of my listed files, but rather to crate a running total.
> 
> I.E., Tune #1 length is 90 seconds, Running total is 90 seconds.
> 
> ```
> Tune #2 length is 208 seconds. Running total is 298 seconds.
> Tune #3 length is 104 seconds. Running total is 402 seconds, etc.
> 
> ```
> 
> I am trying to add the length of the current tune in the loop to the time total of the _preceding_ tunes.

Try this:

```
$loop(%track%)$puts(RunTotal,$add(%_length_seconds%,$get(RunTotal)))%_length_seconds%*$get(RunTotal)*
$loopend()

```

---

<div class="post-metadata">

### Author: ![pdwhite](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@pdwhite](https://community.mp3tag.de/u/pdwhite)
#### Post date: [December 3, 2016, 11:11pm UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481/5 "2016-12-03T23:11:48Z")

</div>

Thank you ryerman. I will try as you suggest.

But this raises another question. Why isn't this stuff, (namely the use of '\*') documented somewhere? Or am I missing something?

Is this an implicit part of MP3TAG scripting, or is the scripting used by MP3TAG a subset of another scripting language?

If it is, please let me know what language it is based on.so I can refer to it.

Again, thank you for your reply. I hope it resolves the issue. 🙂

---

<div class="post-metadata">

### Author: ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)
#### Post date: [December 4, 2016, 2:09am UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481/6 "2016-12-04T02:09:47Z")

</div>

> [@PDWhite](#):
>
> But this raises another question. Why isn't this stuff, (namely the use of '\*') documented somewhere? Or am I missing something?

"\*" has no special meaning here. It did nothing to manipulate data. It is not a wild-card.  
I used it merely as a separator for the output, which you will see if you try the export script.  
It could have been any other non-special character.

Use the "Support" button at the top of the forum to find lots of documentation.  
eg. [https://docs.mp3tag.de/scripting](https://docs.mp3tag.de/scripting)

---

<div class="post-metadata">

### Author: ![pdwhite](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@pdwhite](https://community.mp3tag.de/u/pdwhite)
#### Post date: [December 4, 2016, 7:33pm UTC](https://community.mp3tag.de/t/use-of-varibles-in-export-scripts/18481/7 "2016-12-04T19:33:13Z")

</div>

Ryerman,

Thank you again. Your code works fine. It is very similar to what I was doing, using the Scripting References Pages as a guide.

The main difference I can see is that I was using $num() to convert the output of %\_length\_seconds% to a numeric value, assuming (incorrectly) that the output would be a string.

You help is greatly appreciated. Thank you!
