mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-23 18:42: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.
|
||||
|
||||
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**:
|
||||
- `Data.getData()` returns a `Map<String, Object>` 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
|
||||
- `Placeholder.saveData()` saves the current data state to the data file.
|
Loading…
x
Reference in New Issue
Block a user