Scripting: return selected option index value from discrete parameters

I have been working on a small scriptlet project and have found myself using some code that could be much more optimal with an update to GPScript. I do accept I may also not be realising there could be a better way to do it and stand ready to be educated!

I am using some discrete parameters. Here is an example:

   paramOffset("Interval Offset") : discrete parameter "unison","+2nd","+3rd","+4th","+5th","+6th","+7th","+8th","+9th","+10th","+11th" = "+5th"

To ascertain and utilise the chosen value I am using this code:

On ParameterValueChanged(p : Discrete, i : Integer) matching param1Offset
        p == "unison" do
            currIntervalIndex = 0
        p == "+2nd" do
            currIntervalIndex = 1
        p == "+3rd" do
            currIntervalIndex = 2
        p == "+4th" do
            currIntervalIndex = 3
        p == "+5th" do
            currIntervalIndex = 4
        p == "+6th" do
            currIntervalIndex = 5
        p == "+7th" do
            currIntervalIndex = 6
        p == "+8th" do
            currIntervalIndex = 7
        p == "+9th" do
            currIntervalIndex = 8
        p == "+10th" do
            currIntervalIndex = 9
        p == "+11th" do
            currIntervalIndex = 10

What would be brilliant (for this type of scenario) would be if the event callback could be declared more like this:

On ParameterValueChanged(p : Discrete, i : Integer, discreteParamIndex : integer) matching param1Offset
    currIntervalIndex = discreteParamIndex 

where the third parameter in the callback function declaration is the index of the discrete parameter that has been selected.

Am I missing an already existing way to do this? Would it be useful for enough use-cases to warrant being added to GPScript?

This function exists:

GetIndexOfDiscreteParameterItem : Find the index of a discrete item and returns -1 if the item is not found

  • Declaration: function GetIndexOfDiscreteParameterItem (p : Discrete, itemToFind : String) returns Integer

This is the page that I find the easiest to search/review existing functions:


Perfect…thank you!