Interactive scripts API #190
felipemanga
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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