From 936a99dafd87e4d5a56074e69e37d5b82b925da0 Mon Sep 17 00:00:00 2001 From: thienbao860 <35884937+thienbao860@users.noreply.github.com> Date: Mon, 11 Jan 2021 17:56:33 +0700 Subject: [PATCH] Updated Advanced Scripts (markdown) --- Advanced-Scripts.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Advanced-Scripts.md b/Advanced-Scripts.md index 199a589..5823985 100644 --- a/Advanced-Scripts.md +++ b/Advanced-Scripts.md @@ -1,6 +1,8 @@ ## Arguments -When calling a JavaScript placeholder, arguments may be supplied for extra functionality. These arguments are included after the placeholder name, and are separated by commas. When included, the arguments are passed to the script through an array called `args`. +When calling a JavaScript placeholder, arguments may be supplied for extra functionality. These arguments are included after the placeholder name, and are separated by commas (`,`) by default, can be changed via [configuration](https://github.com/PlaceholderAPI/Javascript-Expansion/wiki#configuration) + +When included, the arguments are passed to the script through an array called `args`. For example, the arguments in the placeholder `%javascript_example_test,3,args%` would be `test`, `3`, and `args`. @@ -123,6 +125,18 @@ viewCount(); Produces: ![data-example](https://i.imgur.com/rmuRQcQ.png) when parsed for the first and second times for a given player. +**NOTE:** If you have a straight-forward string key, you can use `DataVar` instead of `Data.get(String)`: + +```Javascript +function viewCount() { + var views = DataVar.constantNum // in replacement of Data.get("constantNum") + + return views; +} + +viewCount(); +``` + **Valid Methods**: - `Data.getData()` returns a `Map` of the entire placeholder script's data. - `Data.clear()` removes all data. @@ -130,5 +144,6 @@ Produces: ![data-example](https://i.imgur.com/rmuRQcQ.png) when parsed for the f - `Data.get(key)` returns the value stored under `key`. - `Data.remove(key)` removes a key from the data. - `Data.set(key, value)` stores a `value` under `key`. +- `Data.setIfNull(key, value)` stores a `value` under `key` only if this data doesn't exist in cache. - `Data.isEmpty()` returns true if the data is empty; else false. - `Placeholder.saveData()` saves the current data state to the data file. \ No newline at end of file