diff --git a/Advanced-Scripts.md b/Advanced-Scripts.md index 145a917..01b0eb6 100644 --- a/Advanced-Scripts.md +++ b/Advanced-Scripts.md @@ -76,7 +76,27 @@ Produces: ![server-info-example-picture](https://i.imgur.com/6yxjpsV.png) when t Storing data from within the placeholder script is quite easy. When a placeholder script is called, a `Data` object is passed to it. Whenever the script modifies the object, it is modified in Javascript-Expansion as well, and then saved to a data file. -Here is an example script that... +Here is an example script that stores how many times a placeholder is viewed. + +```Javascript +// Location keys are just like YAML files +var dataLoc = "%player_name%.viewed"; + +function viewCount() { + var views = Data.exists(dataLoc) ? Data.get(dataLoc) : 0; + + views++; + + Data.set(dataLoc, views); + Placeholder.saveData(); + + return views; +} + +viewCount(); +``` + +Produces: ![data-example](https://i.imgur.com/rmuRQcQ.png) when parsed for the first and second times for a given player. **Valid Methods**: - `Data.getData()` returns a `Map` of the entire placeholder script's data. @@ -86,6 +106,4 @@ Here is an example script that... - `Data.remove(key)` removes a key from the data. - `Data.set(key, value)` stores a `value` under `key`. - `Data.isEmpty()` returns true if the data is empty; else false. -- `Placeholder.saveData()` saves the current data state to the data file. - -// IN PROGRESS \ No newline at end of file +- `Placeholder.saveData()` saves the current data state to the data file. \ No newline at end of file