Function: add()
Call Signature
> add(handler): void
Defined in: src/handlers/hashtag-commands.ts:64
Parameters
handler
Returns
void
Deprecated
Use the two-parameter overload with HashtagHandlerOptions instead.
Call Signature
> add(handler, opts): void
Defined in: src/handlers/hashtag-commands.ts:89
This function add a new handler (middleware) that will be called before the system interprets a possible Hashtag-Command that starts with #.
The developer can use this function to run a custom Hashtag-Command. If the function returns true, the system will not interpret the Hashtag-Command.
If returns a array of strings, the system will interpret the array as a new Hashtag-Command.
Parameters
handler
The handler to run a custom Hashtag-Command
opts
HashtagHandlerOptions
Configuration for this handler, including its name, optional description, and validation rule.
Returns
void
Example
import { HashtagScript } from 'pixi-vn-ink'
HashtagScript.add((script, props, convertListStringToObj) => {
// script: # navigate scene_name prop1 "value 1" prop2 "value 2"
if (script[0] === "navigate" && script.length > 1) {
let prop = undefined
if (script.length > 2) {
prop = convertListStringToObj(script.slice(2))
}
navigateTo(script[1], prop)
return true
}
return false
}, { name: "navigate-command", validation: /^navigate\b/ })