Script to add values to a User:Labeled parameter?

Hi everyone!

I’ve got a very long list of values in a spreadsheet that I’d like to be able to make into values in a user:labeled parameter and I’m wondering if it can be done with a script. I’ve tried reading through the scripting examples and the API reference but my programming knowledge is not strong. I am hoping there’s someone on here much smarter than me who can tell me if this is possible and how to do it.

thanks in advance!

Hi,

You can create a labeled parameter using:

var event = studio.window.browserCurrent()
var labeledParam = event.addGameParameter({ 
            name: "NewLabeledParam", 
            type: studio.project.parameterType.UserEnumeration, 
            enumerationLabels: labels, 
            min: 0, 
            max: labels.length 
        });

The labels variable I am using is an array that I created, but this is where you will get the data from your spreadsheet:

var labels = ["One", "Two", "Three"]

Hope this helps!

Hey Connor!
First off, thanks for the reply and the help. I’m running this in the console and it’s creating a labeled parameter but the values of the labels are still the default Value A, Value B, Value C. Am I doing something wrong or misunderstanding your advice? Thanks again!!

var event = studio.window.browserCurrent()

var labels = [“One”, “Two”, “Three”];

var labeledParam = event.addGameParameter({

        name: "NewLabeledParam", 

        type: studio.project.parameterType.UserEnumeration, 

        enumerationLabels: labels, 

        min: 0, 

        max: labels.length 

    });
1 Like

No worries, happy to help!

Testing your code it looks ok:


Could I get a screenshot of the parameter if you try to edit it:

Hmmm that’s interesting! Attaching screenshot in this message


I’m also in 2.02.20 if that has any impact on things…

1 Like

Ah, 2.02.20 was the missing piece. I was able to reproduce the issue.

Is it possible to update to 2.02 latest? The issue is no longer present.

Aaahh ok I’m glad we got to the bottom of it. This is for a project I’m already in the middle of so I’m hesitant to update for its’ builds… we’ll see how fearless I’m feeling. Either way this will be SUPER useful moving forward. Much much appreciated!

1 Like

Totally understandable.

If you do decide to update please let us know if we can assist further!

Thanks @Connor_FMOD, I got inspired :smile: But how do I close the modalDialogWindow.,this.dialog,close returns undefined?

studio.menu.addMenuItem({
    name: "NOM\\Add Labelled Param",
    execute: function () {
        var labelsText = "";
        var paramName = "";
        

            studio.ui.showModalDialog({
            windowTitle: "Add Labelled Parameter",
            widgetType: studio.ui.widgetType.Layout,
            layout: studio.ui.layoutType.GridLayout,
            sizePolicy: studio.ui.sizePolicy.Expanding,
            windowWidth: 400,
            windowHeight: 100,
            items: [
                {
                    widgetType: studio.ui.widgetType.Label,
                    column: 0,
                    row: 0,
                    text: "Parameter Name:",
                    alignment: studio.ui.alignment.AlignTop | studio.ui.alignment.AlignLeft
                },
                {
                    widgetType: studio.ui.widgetType.LineEdit,
                    column: 0,
                    row: 1,
                    text: "",
                    sizePolicy: studio.ui.sizePolicy.Expanding,
                    onTextEdited: function () {
                        paramName = this.text();
                    }
                },
                {
                    widgetType: studio.ui.widgetType.Label,
                    column: 0,
                    row: 2,
                    text: "Enter comma-separated labels:",
                    alignment: studio.ui.alignment.AlignTop | studio.ui.alignment.AlignLeft
                },
                {
                    widgetType: studio.ui.widgetType.LineEdit,
                    column: 0,
                    row: 3,
                    text: "",
                    sizePolicy: studio.ui.sizePolicy.Expanding,
                    onTextEdited: function () {
                        labelsText = this.text();
                    }
                },
                {
                    widgetType: studio.ui.widgetType.PushButton,
                    column: 0,
                    row: 4,
                    text: "Create Labeled Parameter",
                    onClicked: function () {
                        var labels = labelsText.split(",").map(function(label) {
                            return label.trim();
                        }).filter(function(label) {
                            return label.length > 0;
                        });

                        if (labels.length === 0) {
                            studio.system.message("Please enter at least one valid label.");
                            return;
                        }

                        if (!paramName || paramName.trim().length === 0) {
                            studio.system.message("Please enter a valid parameter name.");
                            return;
                        }

                        var event = studio.window.browserCurrent();
                        if (!event) {
                            studio.system.message("No event selected in the browser.");
                            return;
                        }

                        try {
                            event.addGameParameter({ 
                                name: paramName.trim(),
                                type: studio.project.parameterType.UserEnumeration, 
                                enumerationLabels: labels, 
                                min: 0, 
                                max: labels.length - 1
                            });

                             studio.system.message("Labeled parameter added with labels: " + labels.join(", "));
                            
                            
                            
                        } catch (e) {
                            studio.system.message("Error adding parameter: " + e.message);
                        }
                    }
                }
            ]
        });
    }
});

This is an awesome script thank you for sharing!! At the end of the onClicked: function{} just add this.closeDialog();

onClicked: function() {
    // ALL THE CODE INBETWEEN
    this.closeDialog();
}

Please let me know if I can help with anymore scripts!

1 Like

Thanks @Connor_FMOD works like a charm! Not sure why I didn’t get this to work earlier but some foolishness on my part most likely.

Script here plus some bank organising scripts also. https://github.com/nightonmars/FMOD-Organisation-scripts

1 Like

Good to hear it worked!

That is awesome, thank you for sharing those! I would be happy to share some scripts that I have made as well?

2 Likes

Please!! Actually, it’d be great to see a script sub-channel in the forum. I’ve had people reach out to me on Airwiggles about FMOD scripting, but I’m just a happy tinkerer, and a place with actual insight would be awesome!

3 Likes

That is a great idea. I have a few super useful scripts a got from people sharing them, but just because I was lucky to spot them/know the people. Would be awesome to have something a bit more public, a bit like ReaPack is for Reaper

1 Like

I will pass on your suggestions. I will try get those scripts up as soon as I can!