You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, scripts can execute a series of actions like altering a sprite or saving it, but they are limited as they can't request the user for input.
As an example, if I wanted to make a script that blurs the image, the script can't show a dialog that asks how much (the blur radius).
Here is my proposal for a scripting API that allows for more complex scripts to be made:
1- Allow scripts to listen for events. Clicking on a script in the menu triggers the "run" event. Clicking on a button in a dialog triggers that custom button's event. We can also have events for notifying the script that it has become selected as the current tool, mouse down/up/move in the sprite (allowing scripts to implement custom brushes), etc. As is the current behavior, the scripting engine will tear-down and clean up after an event is handled. We can avoid this as an optimization for mouse events, if it is necessary to prevent lag.
2- Addition of a new script object that serves as a key-value storage for scripts. This will allow scripts to maintain state information between executions or share data with other scripts. It will contain the following methods:
script.event: returns the name of the event that invoked the script.
script.get(string key, string namespace = script.fileName): Get a previously saved Value, with an optional namespace. By default, the namespace is the name of the currently executing script (allowing scripts to use their own key-value stores by default, but able to access shared stores).
script.set(string key, Value value, string namespace = script.fileName): Stores a Value associated with a Key, optionally specifying a namespace.
script.setURL(string key, string URL, string namespace): retrieves the contents of URL and stores it in key. Raises the "${key}-set" or "${key}-${errorcode}" event. This allows us to make the script sharing gallery or lospec integration.
3- Addition of a new Dialog class that can be used to interact with the user.
Example script that opens a dialog and counts how many times a button was pressed:
if(script.event=="run"){createDialog();}elseif(script.event=="buttonOK-pressed"){letdialog=app.getDialog("test");letinputValue=dialog.getChild("value");letlabelCaption=dialog.getChild("caption");letvalue=inputValue.value();// get the number entered in the input fieldlabelCaption.setLabel("You pressed OK "+count+" times. Value is "+value);}functioncreateDialog(){// opens a new dialog windowletdialog=app.openDialog();// put a label inside the dialog. Last argument "caption" is an optional Id for retrieving the label later.dialog.addLabel("This is a label","caption");// add number input with a label and an Id. Emits the "${id}-changed" event.dialog.addNumberInput("Enter a value:","value");// create a button with an "OK" label and "buttonOK" id. Emits the "${id}-pressed" event.dialog.addButton("OK","buttonOK");}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Right now, scripts can execute a series of actions like altering a sprite or saving it, but they are limited as they can't request the user for input.
As an example, if I wanted to make a script that blurs the image, the script can't show a dialog that asks how much (the blur radius).
Here is my proposal for a scripting API that allows for more complex scripts to be made:
1- Allow scripts to listen for events. Clicking on a script in the menu triggers the "run" event. Clicking on a button in a dialog triggers that custom button's event. We can also have events for notifying the script that it has become selected as the current tool, mouse down/up/move in the sprite (allowing scripts to implement custom brushes), etc. As is the current behavior, the scripting engine will tear-down and clean up after an event is handled. We can avoid this as an optimization for mouse events, if it is necessary to prevent lag.
2- Addition of a new
script
object that serves as a key-value storage for scripts. This will allow scripts to maintain state information between executions or share data with other scripts. It will contain the following methods:script.event
: returns the name of the event that invoked the script.script.get(string key, string namespace = script.fileName)
: Get a previously saved Value, with an optional namespace. By default, the namespace is the name of the currently executing script (allowing scripts to use their own key-value stores by default, but able to access shared stores).script.set(string key, Value value, string namespace = script.fileName)
: Stores a Value associated with a Key, optionally specifying a namespace.script.setURL(string key, string URL, string namespace)
: retrieves the contents of URL and stores it in key. Raises the "${key}-set" or "${key}-${errorcode}" event. This allows us to make the script sharing gallery or lospec integration.3- Addition of a new
Dialog
class that can be used to interact with the user.Example script that opens a dialog and counts how many times a button was pressed:
Beta Was this translation helpful? Give feedback.
All reactions