mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-24 20:02:44 +00:00
Added example for storing data
parent
14e89492d4
commit
e5c0ebd9fd
@ -76,7 +76,27 @@ Produces:  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.
|
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:  when parsed for the first and second times for a given player.
|
||||||
|
|
||||||
**Valid Methods**:
|
**Valid Methods**:
|
||||||
- `Data.getData()` returns a `Map<String, Object>` of the entire placeholder script's data.
|
- `Data.getData()` returns a `Map<String, Object>` of the entire placeholder script's data.
|
||||||
@ -87,5 +107,3 @@ Here is an example script that...
|
|||||||
- `Data.set(key, value)` stores a `value` under `key`.
|
- `Data.set(key, value)` stores a `value` under `key`.
|
||||||
- `Data.isEmpty()` returns true if the data is empty; else false.
|
- `Data.isEmpty()` returns true if the data is empty; else false.
|
||||||
- `Placeholder.saveData()` saves the current data state to the data file.
|
- `Placeholder.saveData()` saves the current data state to the data file.
|
||||||
|
|
||||||
// IN PROGRESS
|
|
Loading…
x
Reference in New Issue
Block a user