VIEWPORT || How can I .getItemText() or something similar??
-
Im trying to script a "delete" preset button but I need to get the item name of the selected index of my viewPort panel. Does anybody know how?
Here's my delete script that doesnt get passed getting the name. This same script works for combobox but I switched it to a viewport panel and I cant get it to work without getting the name.
please help
Thanks!inline function onbtnSynthDeletePresetControl(component, value) { if (!value) return; //------------------------------------------------------------------- local selectedIndex = vpSynthPresets.getValue(); Console.print(selectedIndex); if (selectedIndex <= 0) return; //------------------------------------------------------------------- // Get preset name //-----------------THIS HERE NOT WORKING----------------------// reg presetNameToDelete = vpSynthPresets.getItemText(); // THIS NOT WORKING HERE Console.print(presetNameToDelete); if (!isDefined(SynthAndFXPresetsFile[presetNameToDelete])) return; //------------------------------------------------------------------- Engine.showYesNoWindow("Delete Preset", "Are you sure you want to delete \"" + presetNameToDelete + "\"?", function(result) // nested callback { var thisValueNOW = vpSynthPresets.getValue(); if (result) // IF 'YES' { var newPresets = {}; for (k in SynthAndFXPresets) { if (k != presetNameToDelete) newPresets[k] = SynthAndFXPresets[k]; } //------------------------------------------------------------------- SynthAndFXPresets = newPresets; //------------------------------------------------------------------- SynthAndFXPresetsFile.writeObject(SynthAndFXPresets); //------------------------------------------------------------------- var keyListSynth = []; // Create array for key names for (k in SynthAndFXPresets) // Get key names from .json object keyListSynth.push(k); // Push names to array //------------------------------------------------------------------- vpSynthPresets.set("items", keyListSynth.join("\n")); // Populate Combobox //------------------------------------------------------------------- vpSynthPresets.setValue(thisValueNOW + 1); // Set to preset previous //------------------------------------------------------------------- lblSynthNameToSave.set("text", ""); // Clear text } }); }; Content.getComponent("btnSynthDeletePreset").setControlCallback(onbtnSynthDeletePresetControl);
-
@Chazrox I assume the viewport is populated from an array? If so, you can use the item index to get the value from the array.
Use
local
inside inline functions rather thanreg
. -
@d-healey this also worked!
-
C Chazrox has marked this topic as solved