API Studio Scripting: play a sound when build is complete

Hi there,

I am looking to write a very simple js script that can play an FMOD Studio Event after having built banks (a notification sound of sorts).
I have got the build banks working but I don’t understand how the Event.play() function works. The reference manual doesn’t give much away, at least given my limited experience with coding and javascript.

Can anyone help? Thank you :slight_smile:

Btw, in the example below I am simply trying to adapt a script I found online to make it play a sound.

var eventID = “{280ded2a-2a06-47c0-b8e5-ff197563243d}”;
var event = studio.project.lookup(eventID);

function doBuild() {
console.log(“Build started”);
studio.project.build();
Event.event.play();
console.log(“Build finished”);
}

var buildAndPlaySound = {
name: “Automation”,
execute: function(){ doBuild(); }
};

var automationMissing = true;
var menuItems = studio.menu.menuItems();
for (var i = 0; i < menuItems.length; ++i) {
if (menuItems[i].name == buildAndPlaySound
.name) {
automationMissing = false;
break;
}
}

if (automationMissing) {
studio.menu.addMenuItem(buildAndPlaySound
);
}
else if (studio.system.question(“Do you want to build?”)) {
doBuild();
}

You almost have it- you need to have the event selected to be able to play it back;

function doBuild() {
    console.log("Build started");
    studio.project.build();
    var event = studio.project.lookup("event:/UI/Okay");
    studio.window.triggerAction(studio.window.navigateTo(event));
    event.play();
    console.log("Build finished");
}

Many thanks Jeff,

that worked!

1 Like