Updated Your First Script (markdown)

thienbao860 2021-01-11 17:18:45 +07:00
parent 7c4c781ea1
commit c21228c358

@ -1,6 +1,6 @@
## Creating Your Script ## Creating Your Script
JavaScript-Expansions are all written in JavaScript (as the name implies). JavaScript-Expansions scripts are all written in JavaScript coding language (as the name implies).
Here is an example "Hello, world!" script: Here is an example "Hello, world!" script:
@ -13,22 +13,24 @@ helloWorld();
``` ```
As you can see, the scripts return one value. As you can see, the scripts return one value.
**NOTE: ** Semicolons (`;`) are not required in JS language. However, this is required with multiple statements stacked in 1 line of script
## Using Your Script ## Using Your Script
To use our hello_world script, first let's save the above as `hello_world.js` inside the `plugins/PlaceholderAPI/javascripts/` folder. To use our hello_world script, first let's save the above as `hello_world.js` inside the `plugins/PlaceholderAPI/javascripts/` folder.
Next, add it to the `plugins/PlaceholderAPI/javascript_placeholders.yml` file so the expansion knows to load it! Next, add it to the `plugins/PlaceholderAPI/javascript_placeholders.yml` file so the expansion knows to load it!
Specifying script engine is optional, as it will be defaulted to 'nashorn' if not initialized
```YAML ```YAML
hello_world: hello_world:
file: hello_world.js file: hello_world.js
engine: nashorn #optional, can be deleted
``` ```
Then, after reloading PlaceholderAPI plugin (`/papi reload`) you can use your placeholder! Then, after reloading with JS-Expansion command (`/jsexpansion reload`) or PlaceholderAPI plugin (`/papi reload`), you can use your placeholder!
To test it, run `/papi parse me %javascript_hello_world%` To test it, run `/papi parse me %javascript_hello_world%` (doesn't work in console)
And ta-da! ![example](https://i.imgur.com/1RdtmUR.png) And ta-da! ![example](https://i.imgur.com/1RdtmUR.png)