Skip to content

DataStorage

Francisco Dias edited this page Jan 30, 2023 · 3 revisions

Back To Top

Sync saved games, user-created levels, debug logs save any bit of data to the player's account, or globally for your game. The clouds are the limit!

Functions

The following functions are provided for working with cloud data storage:

Other

Extra information regarding the data storage functions:




Back To Top

This function fetches data from the user data storage. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Fetch(key, [callback_success], [callback_failed])
Argument Type Description
key string The identifier key of the data
callback_success function The callback function executed if the request succeeds (value is passed as argument) ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Fetch("heroLevel",
    function(data)
    {
        heroLevel = real(data);
    },
    function(message)
    {
        show_message_async(message)
    });

In the code sample above we perform a fetch action to retrieve the user data stored with the key "heroLevel", we then provide two methods the success method will display the value associated with that key and the failure method will show a message with the error information.




Back To Top

This function fetches data from the global data storage. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Fetch_Global(key, [callback_success], [callback_failed])
Argument Type Description
key string The identifier key of the data
callback_success function The callback function executed if the request succeeds (value is passed as argument) ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Fetch_Global("lastBossKillCount",
    function(data)
    {
        bossKillCount = real(data);
    },
    function(message)
    {
        show_message_async(message)
    });

In the code sample above we perform a fetch action to retrieve the global data stored with the key "lastBossKillCount", we then provide two methods the success method will display the value associated with that key and the failure method will show a message with the error information.




Back To Top

This function fetches keys of data items from the user data storage. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_GetKeys(pattern, [callback_success], [callback_failed])
Argument Type Description
pattern string The pattern to apply when querying existing keys
callback_success function The callback function executed if the request succeeds (arrays of strings is passed as argument) ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_GetKeys("*",
    function(array)
    {
        show_message_async(array);
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform a fetch action to retrieve the keys from the user data storage , that follow the pattern "*" (meaning all ). We then provide two methods: the success method will display the array of existing keys and the failure method will show a message with the error information.




Back To Top

This function fetches keys of data items from the global data storage. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_GetKeys_Global(pattern, [callback_success], [callback_failed])
Argument Type Description
pattern string The pattern to apply when querying existing keys
callback_success function The callback function executed if the request succeeds (arrays of strings is passed as argument) ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_GetKeys_Global("*",
    function(array)
    {
        show_message_async(array);
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform a fetch action to retrieve the keys from the global data storage , that follow the pattern "*" (meaning all ). We then provide two methods: the success method will display the array of existing keys and the failure method will show a message with the error information.




Back To Top

This function removes data items from the user data store. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Remove(key, [callback_success], [callback_failed])
Argument Type Description
key string The identifier key of the data
callback_success function The callback function executed if the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Remove("hasArrows",
    function()
    {
        show_message_async("Success!!");
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform an action to remove a key ("hasArrows") from the user data storage . We then provide two methods that will display the success of failure of the task.




Back To Top

This function removes data items from the global data store. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Remove_Global(key, [callback_success], [callback_failed])
Argument Type Description
key string The identifier key of the data
callback_success function The callback function executed if the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Remove("gameoverCount",
    function()
    {
        show_message_async("Success!!");
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform an action to remove a key ("gameoverCount") from the global data storage . We then provide two methods that will display the success of failure of the task.




Back To Top

This function sets data in the user data store. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Set(key, data, [callback_success], [callback_failed])
Argument Type Description
key string The identifier key of the data
data real/string/struct The data value to associate with the provided key
callback_success function The callback function executed if the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Set("name", "HERO"
    function()
    {
        show_message_async("Success!!");
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform an action to set a key ("name") from the user data storage to a specific value ("HERO"). We then provide two methods that will display the success of failure of the task.




Back To Top

This function sets data in the global data store. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Set_Global(key, data, [callback_success], [callback_failed])
Argument Type Description
key string The identifier key of the data
data real/string/struct The data value to associate with the provided key
callback_success function The callback function executed if the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Set_Global("gameoverCount", 2
    function()
    {
        show_message_async("Success!!");
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform an action to set a key ("gameoverCount") from the global data storage to a specific value (2). We then provide two methods that will display the success of failure of the task.




Back To Top

This function updates user data in the data store applying a selected operation. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Update(key, data, operation, [callback_success], [callback_failed])
Argument Type Description
key string The identifier key of the data
data real/string/struct The data value used by the operation
operation string The operation to be performed with the provided data (see Operations Table)
callback_success function The callback function executed if the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Update("currentLevel", 1, "add"
    function()
    {
        show_message_async("Success!!");
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform an action to update a key ("currentLevel") from the user data storage using the "add" operation and passing a given amount 1. We then provide two methods that will display the success of failure of the task.




Back To Top

This function updates global data in the data store applying a selected operation. This is an asynchronous function that will trigger either the callback_success method (if task is successful) or the callback_failed method (if task fails).


Syntax:

GameJolt_DataStorage_Update_Global(key, data, operation,  [callback_success], [callback_failed])
Argument Tyoe Description
key string The identifier key of the data
data real/string/struct The data value used by the operation
operation string The operation to be performed with the provided data (see Operations Table)
callback_success function The callback function executed if the request succeeds ✴️ OPTIONAL
callback_failed function The callback function executed if the request fails (error message is passed as argument) ✴️ OPTIONAL

Returns:

N/A

Example:

GameJolt_DataStorage_Update("gameoverCount", 1, "add"
    function()
    {
        show_message_async("Success!!");
    },
    function(message)
    {
        show_message_async(message)
    }
)

In the code sample above we perform an action to update a key ("gameoverCount") from the global data storage using the "add" operation and passing a given amount 1. We then provide two methods that will display the success of failure of the task.




Back To Top

This is a table of operations that the developer can perform on data stored inside the GameJolt cloud storage system. These operation are to be used with the functions:

Operation Description
"add" Adds the value to the current data store item (reals only).
"subtract" Subtracts the value from the current data store item (reals only).
"multiply" Multiplies the value by the current data store item (reals only).
"divide" Divides the current data store item by the value (reals only).
"append" Appends the value to the current data store item.
"prepend" Prepends the value to the current data store item.