Is there a way to set button text from script?
-
BTW - I tried this to see what "obj" has available and it bugs the console out:
Console.print(trace(obj));It prints but the console gets stuck and will not scroll up, it just forces its way back down to the bottom.
-
@VirtualVirgin You can set almost any property of a component using the .set function.
-
As @d-healey already said, you can determine the text with the set function.
Since you wanted to use trace(obj), I assume that you want to use LookAndFeel for the buttons. The console does not get stuck. Instead, the buttons are painted continuously when they are visible and the console is therefore always refilled, which is why you cannot scroll upwards.
This is the information you get from buttons using trace(obj):
Interface: { "id": "Button1", "area": [ 0.0, 0.0, 128.0, 28.0 ], "enabled": true, "text": "This is your text", "over": false, "down": false, "value": false, "bgColour": 1442840575, "itemColour1": 1714631475, "itemColour2": 4212199697, "textColour": 4294967295, "parentType": "ScriptContent", "parentName": "" }
And here is a snippet that demonstrates how you can use the set function and paint your buttons:
HiseSnippet 1029.3ocsV0uaaaCDmxIpXVaqXEsO.D9ujGLb8WowCECKINwaAKI0X1qX.CCEzTmrYiLoAEcRMF56xdT1izdC1NpOrUhSSSLvHLLz88Od7tibfVwg3Xkl33MZ4bf37UtCWJMS6MkIjjSOl37T2yYwFPSSYczx4r3XHf33ryOZY3TdWRx5e9giXQLIGVyhPdqRvgyDyDl0bGbvOKhh5yBfQhYEztyAmxUxdpH0BDO631fLmwujMAtfYUqjK4mXwSINeqaaHnU2tr85ztMu620kuOm0E3MGueiVrvf1cgfwAc1qCi37jSBDFkdngYfXzoGoBVNbp5ZYZ.dqHVLNBrDMICwHmxlzapHJXPdxIlPb1cv5T0NoopW3dtHPrh+5T12jHft1hhIMmR2GjZ9HfjSAHsaJjdl6PtVL2rVhEOeo6oR7DLjgmMEgRptjRc2wsmB0PZpOicIzWiDqrv+UMZTih+U80ddu7kziVXLJYLko0rkd3AVrYEuum964NZBX5olMWIQB+JoJzrR0ZdzautOKZUo5ejF1dZ.yWzyTpKOTFzGfHpeDKrZFBvOwnm6Jdhxmo3rnBF3msCFBFpA9fgpBolo.cbJ58BUZ+wTgLe6T0q735w.BFq1UpQqLZpHlh+VhUnItnB5xx49L0OEg3mzka.M6VIEcE2gZXhHo2KbgjaDJoGpW8bt8yX5WIPytdjZxjHHMNHVysveRMpZ76q58mdkuhooLLMgz0YXJxh8xhPeK8UrnE.BuxSpGhcmGFE4m1IFWOfouLNBSnSzvR6FFhhg6TybE7PYw1iSK6URudpv.4hsP9vHwDIDLBSjIXvlQqQYXhlimhZHvld+X0WmuWnJ4EJC7Foex1w6idzaKJL7NkYKLzpnHPemhsygz2mg9xEyFC5ZzrzTlhXe2MalexCqYlmVmVPQk7Tov7l4PFceUTfsI098ls9jrBcbHPoLDhpZRFA7zrQ.oUBDA5jxtY8ejD3WbjM4QXdqaaNt90SOlYX1gQYPBg4bPaD1rgywvU33+zQSkcOFhuznlmf4r9bhi6C.0eXUH+6nCVtN9xCrULDmm6tQioME8HhQqOUL9Ky8EiMG.ii9UAKvlkadef8lxLAXc0MFBaGzJiElkEOVdDWRz3duj3gBwm4NPX3SuaLV5Nvnsz6+ALlc05W6dRXHvMqA3tt8+ss8dzOS3+E0BiPN4blQKvx.2KVLaHdFyAL5RINrC44Tx10kR2vRay.CAYPBw+hqLgMszNYBalKjLiw0p2wSa1rWd+EIbPLISdbSY7UVHMs4l8Xyv2R7NN+ltZCCassF1daMry1Z3daqguZaMb+s0vtedCsO06vEF0rz1FB47AmjLSzw4DICq.SpVI+WWn2CD
-
So this is working to set text:
//Loop to set C note numbers for (i = 0; i < fullKeyboard0.length; i++) fullKeyboard0[i][0].set("text", "C" + i);
But when I run a test to set the id of components:
OneOctaveKeyboard0[0].set("id", "Test");
I get:
Interface:! Line 243, column 26: the property doesn't exist
-
@VirtualVirgin You can't change a component's ID.
-
@d-healey said in Is there a way to set button text from script?:
@VirtualVirgin You can't change a component's ID.
So there is no way to change the ids programmatically?
I have a use case for changing the numbering after multiple components are created. -
@VirtualVirgin IDs are fixed, once they can only be changed in the property editor. They can't be changed dynamically.
-
@d-healey said in Is there a way to set button text from script?:
@VirtualVirgin IDs are fixed, once they can only be changed in the property editor. They can't be changed dynamically.
My issue is that the black keys must be on top (to get the click of the button), so the ordering in the Component List turns out like this:
When octaves are multiplied, and of course the whole keyboard as well, they stay in the right order for the buttons to work, but the auto-numbering will take them out of order for the "Key" names to match MIDI note numbers.
I take it if I just ignore the "Key" numbering beyond the basic level, then I could reassign them all to indexes in an array that match the MIDI note numbers with some modulo math.
I'd have to live with "Key1" being MIDI note # 2 though, etc...
-
@VirtualVirgin I'm not 100% sure what you're doing, but it sounds like you're adding components dynamically at run time (after on init), if that is the case I think you'll run into issues.
If you want to change which components appear on top of one another you can use
setZLevel()
. -
@d-healey said in Is there a way to set button text from script?:
@VirtualVirgin I'm not 100% sure what you're doing, but it sounds like you're adding components dynamically at run time (after on init), if that is the case I think you'll run into issues.
If you want to change which components appear on top of one another you can use
setZLevel()
.Not trying to create them dynamically, just trying to make it easy to copy and paste in order to use multiple keyboard instances in the same interface when needed.
I think this "setZLevel()" will do the trick for the current problem :)
I can just put them back in numbered order and set the Z with a loop. -
@VirtualVirgin said in Is there a way to set button text from script?:
Not trying to create them dynamically, just trying to make it easy to copy and paste in order to use multiple keyboard instances in the same interface when needed.
If you can it would be good to share more details about what you're wanting to achieve, I'm sure there is a simpler way than using lots of buttons. If a single panel can't do it, then perhaps using child panels which can be created/removed dynamically.
-
@d-healey said in Is there a way to set button text from script?:
@VirtualVirgin said in Is there a way to set button text from script?:
Not trying to create them dynamically, just trying to make it easy to copy and paste in order to use multiple keyboard instances in the same interface when needed.
If you can it would be good to share more details about what you're wanting to achieve, I'm sure there is a simpler way than using lots of buttons. If a single panel can't do it, then perhaps using child panels which can be created/removed dynamically.
I'll just continue making it my way for the moment for the sake of completion, then I'll send the snippet for the keyboard.
-
@d-healey said in Is there a way to set button text from script?:
@VirtualVirgin I'm not 100% sure what you're doing, but it sounds like you're adding components dynamically at run time (after on init), if that is the case I think you'll run into issues.
If you want to change which components appear on top of one another you can use
setZLevel()
.The function for:
ScriptButton.setZLevel(String zLevel)
Does not appear to be working.
Here is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