Mod Creation/Mod Context API Reference: Difference between revisions

Line 585: Line 585:


== Account Data Storage ==
== Account Data Storage ==
The account storage API can be accessed through the <code>accountStorage</code> property on the root context object.
The account storage API can be accessed through the <code>accountStorage</code> property on the root context object.


=== Limitations ===
=== Limitations ===
Due to the cloud-based nature of how account data is stored and potential network issues the player may experience, data integrity is not 100% guaranteed in the account storage. Account storage is advised to be used sparingly.
Due to the cloud-based nature of how account data is stored and potential network issues the player may experience, data integrity is not 100% guaranteed in the account storage. Account storage is advised to be used sparingly.


An account can store up to 8,192 bytes (8kb) of data per mod, including keys. Only JSON-serializable data can be stored. This includes primitive types (<code>string</code>, <code>number</code>, <code>boolean</code>) and objects and arrays that contain only primitive types or other objects or arrays that fit this description. This serialization/deserialization is handled automatically.
An account can store up to 8,192 bytes (8kb) of data per mod, including keys. Only JSON-serializable data can be stored. This includes primitive types (<code>string</code>, <code>number</code>, <code>boolean</code>) and objects and arrays that contain only primitive types or other objects or arrays that fit this description. This serialization/deserialization is handled automatically.


=== <code>setItem(key: string, data: any): void</code> ===
=== setItem(key: string, data: any): void ===
 
Sets a key/value pair in account storage.
Sets a key/value pair in account storage.


Line 602: Line 605:


'''Example'''
'''Example'''
  <nowiki>ctx.accountStorage.setItem('coolThings', ['rocks']);</nowiki>
  <nowiki>ctx.accountStorage.setItem('coolThings', ['rocks']);</nowiki>


=== <code>getItem(key: string): any</code> ===
=== getItem(key: string): any ===
 
Gets a value by its key from account storage.
Gets a value by its key from account storage.


Line 616: Line 621:


'''Example'''
'''Example'''
  <nowiki>ctx.accountStorage.getItem('coolThings'); // returns ['rocks']</nowiki>
  <nowiki>ctx.accountStorage.getItem('coolThings'); // returns ['rocks']</nowiki>


=== <code>removeItem(key: string): void</code> ===
=== removeItem(key: string): void ===
 
Removes a key/value pair by key from account storage.
Removes a key/value pair by key from account storage.


Line 626: Line 633:


'''Example'''
'''Example'''
  <nowiki>ctx.accountStorage.removeItem('coolThings');
  <nowiki>ctx.accountStorage.removeItem('coolThings');
ctx.accountStorage.getItem('coolThings'); // returns undefined</nowiki>
ctx.accountStorage.getItem('coolThings'); // returns undefined</nowiki>


=== <code>clear(): void</code> ===
=== clear(): void ===
 
Removes all key/value pairs from account storage.
Removes all key/value pairs from account storage.


'''Example'''
'''Example'''
  <nowiki>ctx.accountStorage.clear();</nowiki>
  <nowiki>ctx.accountStorage.clear();</nowiki>


91

edits