Skip to content

Commit 01776e2

Browse files
Merge pull request #48 from minosimo/patch-20
Clarify scriptPanel data persistence and add example
2 parents df0dcc8 + 5b09a04 commit 01776e2

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

scripting/scripting-in-hise/scriptpanel.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,9 @@ const var Panel2 = createPanel("Panel2", 150, 0);
365365

366366
The `this` keyword is only meaningful inside the three callbacks, but it allows a totally encapsulated widget.
367367

368-
### Control Data
369-
370-
The control data is the data that actually represents the current value of the widget:
371-
372-
- `1` / `0` for toggle buttons
373-
- `double` numbers for slider types
374-
- `int` numbers for discrete widgets like combobox selectors.
375-
376-
You access and store **Control Value** just like with any other UI type in HISE: using the `setValue(value)` / `getValue()` methods. This feature is deactivated by default, so if you create a UI widget that uses a **Control Value**, you have to set the `saveInPreset` property of the Panel to `true`
368+
Values stored in `data` are always non-persistent even if the panel has `saveInPreset` set to true.
377369

378-
It's heavily recommended that this will be just a simple number, but you can choose to use more complex types if your widget that demands that (we'll cover this case in a example later on). But even then it might be more efficient to store the actual value as an array in the `data` object and use the **Control Value** as index:
370+
It's heavily recommended to store a simple number whenever possible, but you can choose to use more complex types if your widget demands it (we'll cover this case in a example later on). Even then it might be more efficient to store the possible values as an array in the `data` object, and use the **Control Value** as an index:
379371

380372
```javascript
381373
// Not very efficient
@@ -386,6 +378,22 @@ this.data.values = ["First Item", "Second Item", "Third Item"];
386378
this.data.setValue(0);
387379
```
388380

381+
### Control Data
382+
383+
In other UI controls, the control data is the data that actually represents the current value of the widget, which can be set and accessed with the `getValue()` and `setValue()` methods:
384+
385+
- `1` / `0` for toggle buttons
386+
- `double` numbers for slider types
387+
- `int` numbers for discrete widgets like combobox selectors.
388+
389+
Panels also support storing and getting their value with `setValue(value)` / `getValue()`, but as a panel is a generic control, this will not be reflected in any way on the UI. Also, panels have `saveInPreset` set to false by default. Enabling `saveInPreset` on a panel makes it useful as a place to persistently store objects, numbers, or booleans. Strings cannot be saved to Control Data, but can be encapsulated inside an object if circumstances require saving a persistent string.
390+
391+
Snippet demonstrating making a value persistent using a panel:
392+
393+
```
394+
HiseSnippet 1233.3ocsVs0aiTCE1SaGXSfshUhmQVyKjVhZSBYaK6BhcaZKa.ZaDoag2V43wSGSmXOx1oYip5+Y9G.GamIYRZJKphcdHJ9b86bwmi6ojTlVKUnfpWLImgB97v9SDlzNoDt.08HTvlgmRzFlB6Ic3jbhVyhQAAq+SVBAU1.499qe7PRFQPYyIgPWJ4T1uxGxMyo16U+BOK6DRL6B9vRR29UcoRQGYlbDfm0CafxIzqIWwNiXEasPzaH5TTv1gwMa2L4.JYuCZ1tEk15f8a8c6SYjjD1dMe99sOHocBg1nEJ3SNNlajp9FhgoQAabnLdR+T4Xg2AWx07AYL6gln9fm8jOQlEaCQKUTmTdVbuhDkFAVo27z159z1WFdJOlOi97z2W3XfmqQ4DXvZKBu0W.dMKCuFkf2JfTPIHsgGROKrOUwyMy4XwymE1U.USH8vV.JdYQqsYXXGIHgvryPx0rSTvgYZTqUiF0wMazXqWVEjRKyX6PyXDUMf.T6zFbNQvxv+.tvHj33dVR0hbbhpiAKzXl3CFYLRwhxeniVsHOun5MpumUgpNCrilYpEoI2v5J5oXvon5F0HFHfW9UIPBISCRf2c2KRYE9jRxxF.MXXcpbTVLVJxlfS3JFdbJCXmwoWyhqVUwtBmyTZt1BvKIJ.sQQVi86fnDgAaR4Z7MDEm.EKrQhGvJoQ0R.yFkJYVmottlmy4hozgffKx3BFNYjfZ3.JWRhZT4vbo.LacviYPbea0JPXwduABHgPZrNWC8TrXKRbxTGqkXt4q03wJRdNvgKvDAVN3OYTS0J.v5UJ.AMpcqAr3KhdCKKSBwGCxJtef.UKGxvwDCI5N.u2U8dPdElaJTgbFXQH0LSXK3O2l3Akr9wCXrLwcvWwwuF.w34DlW4f.btd9z+NUqLqOorueYAcZJQbEKtlqcnCYjloe.Sa6Erw2L6sb0ywnbwa2cOjQslDWt+ykzrvDxjJa0XlSrdPCMd3LIIFz9LoA5eRI9PZIw1lj.WC2FDuqfCk+wobZJdHiHzKjAvWwLfQugoFq3FnFf4I3IxQfymTjw3FaKf2R2q9sXXsxNtkuO3X.o3hgB4Jt.tEZY5X8BbD9a..Xmgrfta4agl4aovlCNWTaqpfa.V3kYkjrRdSQaFSsR11MMp+MEqIFMb.SUDiEBBSSWbDc3COht7FDpebVIA8I6yyYhGZuBZ5LP637onBD03Fl+zhg41ZChCir+zPWcB4vKJ3qB+49me1sQ16sQP59Lo6Np6VazcHza6dDbrvzfW.OCUBC2FTAGwtA1S62aTI7Hl9ZiLGV41on1CA9GBHuGjIvtGeRweJeIvRyQ79lbyolzO22YymD5m6sjQ+9UXT+SJt21OXuqLdTFwr3xX6SVlx.J+KrAztkSn4lIkeRy+aan+uBwmE1ianoqFiqsBLBkzOFXb56ZdZ3wvipnl4.bivS9iONOhA8axQFt3pSIFE2V3Oazv9vaAoLv6BnEyd8KXMaOj+bih5eelH1c3uguoLaVzwYY1rfIZHgpjui5udYe4zSbT.LIbuxrB7bW3LtYwEq444gvC4dGktnotmhsdrJ9sOVEa+XU74OVE26wp39OVEO3Cqn8c1udjQNzesAgNs2wtYdAAGKrKFccqn+gNTucw
395+
```
396+
389397
Calling `setValue(value)` does not execute the `onControl` callback (for safety reasons). Instead you need to explicitely tell the engine to fire the control callback using the method `Panel.changed()`
390398

391399
# Best Practices

0 commit comments

Comments
 (0)