# Script For Setting Platform Exclusion on All Instances of an Effect

**URL:** <https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945>\
**Category:** FMOD Studio\
**Tags:** javascript\
**Created:** [December 4, 2023, 5:14am UTC](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945 "2023-12-04T05:14:32Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [December 6, 2023, 4:03am UTC](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945/3 "2023-12-06T04:03:04Z")

</div>

> [@JSMallard](#):
>
> Using something like this, I can see what platform are excluded. It looks like this is not a pluginParameter though and changing it would mean changing several values? Ideally, I want to safely switch what platforms are excluded and not.

To add a platform to an effect’s `excludedPlatforms` array, you need to add it via the effect’s relationships - for example:

```auto
// get current platform
var platform = studio.project.workspace.projectSettings.activePlatform;
// add it to the effect's excluded platforms
eventEffect.relationships.excludedPlatforms.add(platform);

```

I’ve modified your script to use the effect’s relationships to toggle whether the Oculus Spatializer effect is excluded from the currently selected plaform. Give it a try and let me know whether you run into any issues.

```javascript
studio.menu.addMenuItem({
    name: "Toggle Oculus Spatializers for Current Platform",
    execute: function() {
		var platform = studio.project.workspace.projectSettings.activePlatform; // get current platform
		var selectedEvents = studio.window.browserSelection();
		// iterate over browser selection
		selectedEvents.forEach(function(event)
		{
			// check whether event is selected
			if (event.isOfExactType("Event"))
			{
				var effectChain = event.masterTrack.mixerGroup.effectChain;
				var effectChainEffects = effectChain.effects;
				// iterate over effects in event's master track
				effectChainEffects.forEach(function(eventEffect)
				{
					// if current effect is a plugin effect
					if (eventEffect.isOfExactType("PluginEffect"))
					{
						// if plugin effect is oculus spatializer
						if (eventEffect.plugin.identifier === "Oculus Spatializer")
						{
							// check whether effect is already excluded so exclusion can be toggled
							var index = platformsArrayIncludes(eventEffect.excludedPlatforms, platform)
							if (index >= 0)
							{
								eventEffect.relationships.excludedPlatforms.remove(platform);
							}
							else
							{
								eventEffect.relationships.excludedPlatforms.add(platform);
							}
									
						}
					}
				});
			}
		});
    },
});

// helper function to check whether platform is already excluded
function platformsArrayIncludes(array, platformToCheck){
	var index = -1;
	array.forEach(function(platform){
		index++;
		if (platform.id === platformToCheck.id) return index;
	});
	return index;
}

```

---

_[View the full topic](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945)._
