Storage.data: Difference between revisions

From RAGE Multiplayer Wiki
(Created page for storage.data)
 
(fixed)
Line 10: Line 10:
mp.storage.data.auth = { token: "abcd" };
mp.storage.data.auth = { token: "abcd" };
mp.storage.flush();
mp.storage.flush();
</syntaxhighlight>
==Known bugs==
There is a bug with ragemp 0.3.7 when if server restarts while player is connected the data property gets nested into a new data field, so mp.storage.data becomes mp.storage.data.data and so on.
<br/>Fix:
<syntaxhighlight lang="javascript">
// author: Shonz1 from ragemp's discord
// region: Fix RAGE:MP storage error (recursive data:...)
let storage = mp.storage.data;
while (storage.hasOwnProperty('data'))
    storage = storage.data;
delete mp.storage.data.data;
Object.getOwnPropertyNames(storage).forEach(key => {
    mp.storage.data[key] = storage[key];
});
mp.storage.flush();
// endregion
</syntaxhighlight>
</syntaxhighlight>
==See also==
==See also==
[[Category:Clientside API]]
[[Category:Clientside API]]

Revision as of 22:28, 10 September 2019

Used to set some client-related data. Saved on the client, see storage.flush() for more details.
Data is saved in <path to RAGEMP>/client_resources/<server ip>/.storage
Thus it is wiped when player deletes client folder.

Syntax

storage.data.someKey = obj;

Example

mp.storage.data.auth = { token: "abcd" };
mp.storage.flush();

See also