# Scripting API: discrete parameter's maximum range value not returning correct value. Bug?

**URL:** <https://qa.fmod.com/t/scripting-api-discrete-parameters-maximum-range-value-not-returning-correct-value-bug/16901>\
**Category:** FMOD Studio\
**Created:** [March 18, 2021, 2:12pm UTC](https://qa.fmod.com/t/scripting-api-discrete-parameters-maximum-range-value-not-returning-correct-value-bug/16901 "2021-03-18T14:12:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matheusab](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/matheusab/32/2028_2.png) [@matheusab](https://qa.fmod.com/u/matheusab)\
**Post date:** [March 18, 2021, 2:12pm UTC](https://qa.fmod.com/t/scripting-api-discrete-parameters-maximum-range-value-not-returning-correct-value-bug/16901/1 "2021-03-18T14:12:42Z")

</div>

(Tested in FMOD 2.01.08)

When I try to get the maximum value from a discrete parameter, I’m getting it’s value incremented by 1.  
When it’s continuous, this problem doesn’t happen though.

The following snippet demonstrates my issue, where the parameter’s type & range are in its name for convenience:

```auto
studio.project.model.Event.findInstances().forEach(function(e){
     e.getParameterPresets().forEach(function(p){
	console.log('name - ' + p.presetOwner.name);
	console.log('min - ' + p.minimum);
	console.log('max - ' + p.maximum);
	console.log('type - ' + p.parameterType);
	console.log('=================================================================');
     });
})

```

Returns:

```auto
name - p_continuous_0-1
min - 0
max - 1
type - 0
=================================================================
name - p_continuous_1-2
min - 1
max - 2
type - 0
=================================================================
name - p_discrete_0-1
min - 0
max - 2
type - 1
=================================================================
name - p_discrete_1-2
min - 1
max - 3
type - 1
=================================================================

```

Is this a bug?

---

<div class="post-metadata">

**Author:** ![aishi](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/aishi/32/82_2.png) [@aishi](https://qa.fmod.com/u/aishi)\
**Post date:** [March 18, 2021, 5:16pm UTC](https://qa.fmod.com/t/scripting-api-discrete-parameters-maximum-range-value-not-returning-correct-value-bug/16901/2 "2021-03-18T17:16:44Z")

</div>

Hi, since discrete values are whole integers, it makes sense if it is giving the non-inclusive max value.

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [March 18, 2021, 11:26pm UTC](https://qa.fmod.com/t/scripting-api-discrete-parameters-maximum-range-value-not-returning-correct-value-bug/16901/3 "2021-03-18T23:26:59Z")

</div>

> [@matheusab](#):
>
> Is this a bug?

No, but I can see why you might think it is.

Under-the-hood, discrete parameters are floating point variables rather than integers, in order to support features such as parameter velocity, seek speed, and parameter value modulation, that gradually change parameter values over time. This means that each value of a discrete parameter is actually a range of values one unit long: the value 1 is the range of values from 1-2, the value 2 is the range of values from 2-3, and so on. Thus, a parameter whose maximum settable value is 2 actually runs all the way to 3.

---

<div class="post-metadata">

**Author:** ![aishi](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/aishi/32/82_2.png) [@aishi](https://qa.fmod.com/u/aishi)\
**Post date:** [March 18, 2021, 11:50pm UTC](https://qa.fmod.com/t/scripting-api-discrete-parameters-maximum-range-value-not-returning-correct-value-bug/16901/4 "2021-03-18T23:50:50Z")

</div>

I stand corrected, thank you for this explanation.

---

<div class="post-metadata">

**Author:** ![matheusab](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/matheusab/32/2028_2.png) [@matheusab](https://qa.fmod.com/u/matheusab)\
**Post date:** [March 30, 2021, 12:06am UTC](https://qa.fmod.com/t/scripting-api-discrete-parameters-maximum-range-value-not-returning-correct-value-bug/16901/5 "2021-03-30T00:06:27Z")

</div>

Oh, I see! Thanks for explaining 🙂
