TurboWarp / scratch-vm

Scratch VM with a JIT compiler and more features
https://turbowarp.org/
Mozilla Public License 2.0
73 stars 68 forks source link

Suggestion: New 'hidden' variable type #121

Open DT-is-not-available opened 1 year ago

DT-is-not-available commented 1 year ago

Adding a 'hidden' variable type to the internal Variable class, that functions identical to a regular scratch variable, but is hidden from the variable list entirely. Why? Extensions would be able to more easily store values inside a project that are used often, for example:

_stageTarget.createVariable('cameraX', 'cameracontrols.cameraX', 'hidden', false)

Then the extension could provide custom reporters or blocks for interacting with these variables, or store them internally for some other purpose, and the value is saved with the project. There is a rather hacky workaround as of right now, however I do not know of possible dangerous effects of saving and loading variables with this property, and it would be nice to have this available as an actual feature:

_stageTarget.createVariable('cameraX', 'cameracontrols.cameraX', '', false)
_stageTarget.variables.cameraX.type = 'hidden'

The workaround works but upon loading a project with 'hidden' variables, the variables discard the custom property which requires them to be reset on project load, which still ends up showing them in the toolbar until it gets reloaded.

If there is already a way to store extension variables, please tell me, I'm typing this in a frenzy at 1 in the morning so I might have missed something or explained poorly.

FurryR commented 10 months ago
util.target.extensionVar = new Map()

is much better.