# Script to extract loop length

**URL:** <https://qa.fmod.com/t/script-to-extract-loop-length/21747>\
**Category:** FMOD Studio\
**Tags:** javascript, studio-scripting-api\
**Created:** [June 10, 2024, 11:33pm UTC](https://qa.fmod.com/t/script-to-extract-loop-length/21747 "2024-06-10T23:33:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RGLD\_O](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@RGLD\_O](https://qa.fmod.com/u/RGLD_O)\
**Post date:** [June 10, 2024, 11:33pm UTC](https://qa.fmod.com/t/script-to-extract-loop-length/21747/1 "2024-06-10T23:33:56Z")

</div>

I wonder if there is a way to obtain the length of a loop region and then store it as a rounded-up int value in the user properties. I have a javascript script that helps me handle accessing and creating user properties for things such as key and tempo:

```
    event.userProperties.every(function (p) {
        //Tempo
        if (p.key === ("Tempo")) {
            p.value = tempoValue;
            tempoExist = true;
        }

// More code 

        return true;
    });

```

Is there a way to get the length of a loop region and then store it as a userproperty? I want to add that I will only ever have a single loop marker per event, no more than that.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [June 12, 2024, 2:02am UTC](https://qa.fmod.com/t/script-to-extract-loop-length/21747/2 "2024-06-12T02:02:03Z")

</div>

An array of marker tracks of an event can be accessed from the member `markerTracks` - each row of logic markers in the editor corresponds to a marker track. You can then access the markers belonging to the track from the markerTrack’s `markers` member. In the case of just wanting to check for loop regions, you can use `.isOfExactType('LoopRegion')` to check whether a marker is a loop region, and then access the region’s position and length from `position` and `length` respectively.

For example, the following script will iterate through all marker tracks for loop regions, and print their names, positions, and lengths to console:

```js
var myEvent = studio.window.browserCurrent();
myEvent.markerTracks.forEach(function(track) {
	track.markers.forEach(function(marker) {
		if (marker.isOfExactType('LoopRegion')){
			console.log("Name = " + marker.name);
			console.log("Position = " + marker.position);
			console.log("Length = " + marker.length);
		}
	});
});

```

For your purposes, it should just be a matter of storing this information, and writing it to the event’s user properties.
