mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-24 20:02:44 +00:00
Initial Tutorial
parent
0b3e9dc2d6
commit
5d9faa4b9e
38
Your-First-Script.md
Normal file
38
Your-First-Script.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
## Creating Your Script
|
||||||
|
|
||||||
|
JavaScript-Expansions are all written in JavaScript (as the name implies).
|
||||||
|
|
||||||
|
Here is an example "Hello, world!" script:
|
||||||
|
|
||||||
|
```JavaScript
|
||||||
|
function helloWorld() {
|
||||||
|
return "Hello, world!";
|
||||||
|
}
|
||||||
|
|
||||||
|
helloWorld();
|
||||||
|
```
|
||||||
|
|
||||||
|
As you can see, the scripts return one value.
|
||||||
|
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
Next, add it to the `plugins/PlaceholderAPI/javascript_placeholders.yml` file so the expansion knows to load it!
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
hello_world:
|
||||||
|
expression: 'file: hello_world.js'
|
||||||
|
type: string
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, after reloading PAPI (`/papi reload`) you can use your placeholder!
|
||||||
|
|
||||||
|
To test it, run `/papi parse %javascript_hello_world%`
|
||||||
|
|
||||||
|
## Advanced Scripts
|
||||||
|
|
||||||
|
You can save data with your script and also access the Bukkit API!
|
||||||
|
|
||||||
|
// coming soon
|
Loading…
x
Reference in New Issue
Block a user