# Correct way to handle build callbacks in script (buildStarted / buildEnded)

**URL:** <https://qa.fmod.com/t/correct-way-to-handle-build-callbacks-in-script-buildstarted-buildended/16602>\
**Category:** FMOD Studio\
**Tags:** javascript\
**Created:** [December 29, 2020, 10:29am UTC](https://qa.fmod.com/t/correct-way-to-handle-build-callbacks-in-script-buildstarted-buildended/16602 "2020-12-29T10:29:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattiaswargren](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mattiaswargren/32/2922_2.png) [@mattiaswargren](https://qa.fmod.com/u/mattiaswargren)\
**Post date:** [December 29, 2020, 10:29am UTC](https://qa.fmod.com/t/correct-way-to-handle-build-callbacks-in-script-buildstarted-buildended/16602/1 "2020-12-29T10:29:29Z")

</div>

I am creating a custom script that build banks to a specific folder, rather than changing the build path in the preferences. The script will then fallback to the default path, not changing the default build behaviour.

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/4/438805a2d1a251b8469c50a7aa4c6cd9e058e2fe.png)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/9/9b7078332a2019333fc0599d7a7e128ef9bbbc1e.png)

Everything works fine except that once you have set the “listeners” to `buildStarted` and `buildEnded`, they live on. So if I build using my script, and then build using F7, the callback functions will run again.

Is there any way to remove the “listeners” to `buildStarted` and `buildEnded`? I can’t seem to find anything in the documentation.

[https://fmod.com/resources/documentation-studio?version=2.1&page=scripting-api-reference-project.html#projectbuildstartedconnectcallback](https://fmod.com/resources/documentation-studio?version=2.1&page=scripting-api-reference-project.html#projectbuildstartedconnectcallback)

I could skip the listeners and rely on the execution order but I rather learn something new. •͡˘㇁•͡˘

```
SetBanksOutputDirectory(outputDirectory);
studio.project.build();
SetBanksOutputDirectory(fallbackDirectory);

```

Thanks  
Mattias

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [January 11, 2021, 9:26pm UTC](https://qa.fmod.com/t/correct-way-to-handle-build-callbacks-in-script-buildstarted-buildended/16602/2 "2021-01-11T21:26:35Z")

</div>

It looks like when the listeners were implemented it was under the assumption these would be done through one-off scripts run through the command line, so decoupling or having them as a one time use function was not considered. Therefore it’s not necessarily a bug, but it’s behaviour can definitely be improved.

I’ve raised a suggestion to improve these functions in a future release, thank you for bringing it to our attention.

---

<div class="post-metadata">

**Author:** ![mattiaswargren](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mattiaswargren/32/2922_2.png) [@mattiaswargren](https://qa.fmod.com/u/mattiaswargren)\
**Post date:** [January 12, 2021, 5:42am UTC](https://qa.fmod.com/t/correct-way-to-handle-build-callbacks-in-script-buildstarted-buildended/16602/3 "2021-01-12T05:42:41Z")

</div>

Thanks for your reply. I skipped the listeners for now.
