GlobalDataStorage

Storage to manage multipurpose data. The Maker and release environment do not share the storage.

# Properties

[{"index":"string Name (ReadOnly)","0":"The name of this GlobalDataStorage."}]

# Methods

[{"index":"int32, List BatchDeleteAndWait(List keys) (ServerOnly) (Yield)","0":"Deletes data with the keys entered. Returns the keys that succeeded in the error code and deletion. Script executions are suspended during the operation."}]

[{"index":"void BatchDeleteAsync(List keys, func> callbackFunction) (ServerOnly)","0":"Deletes data with the entered keys. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the deletion, error code succeeded keys when completing the operation."}]

[{"index":"int32, DataStorageItemPages BatchGetAndWait(List keys) (ServerOnly) (Yield)","0":"Queries data corresponding to the keys entered. You can see the query result with the returned entity. Script executions are suspended during the operation."}]

[{"index":"void BatchGetAsync(List keys, func, DataStorageItemPages> callbackFunction) (ServerOnly)","0":"Inquires about data corresponding to the entered keys. You can see the inquiry result with the returned entity. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code, key, and entity for inquiry when completing the operation."}]

[{"index":"int32, DataStorageItemPages BatchGetByInfoAndWait(List keyInfos) (ServerOnly) (Yield)","0":"Queries data with the DataStorageKeyInfo entered. You can see the query result with the returned entity. Script executions are suspended during the operation."}]

[{"index":"void BatchGetByInfoAsync(List keyInfos, func, DataStorageItemPages> callbackFunction) (ServerOnly)","0":"Acquires the entity that can inquire about data corresponding to the entered DataStorageKeyInfo. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code, key, and entity for inquiry when completing the operation."}]

[{"index":"int32, List BatchSetAndWait(Dictionary keyValues) (ServerOnly) (Yield)","0":"Saves data with the keys entered. Returns the keys that succeeded in the error code and storage. Script executions are suspended during the operation."}]

[{"index":"void BatchSetAsync(Dictionary keyValues, func> callbackFunction) (ServerOnly)","0":"Saves data with the entered keys. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code and storage succeeded keys when completing the operation."}]

[{"index":"int32, List BatchSetByInfoAndWait(Dictionary keyValues) (ServerOnly) (Yield)","0":"Saves data with the DataStorageKeyInfo entered. Returns the DataStorageKeyInfo that succeeded in the error code and storage. Script executions are suspended during the operation."}]

[{"index":"void BatchSetByInfoAsync(Dictionary keyValues, func> callbackFunction) (ServerOnly)","0":"Saves data with the entered DataStorageKeyInfo. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code and storage succeeded DataStorageKeyInfo when completing the operation."}]

[{"index":"int32 DeleteAndWait(string key) (ServerOnly) (Yield)","0":"Deletes data with the entered key and returns the error code. Script executions are suspended during the operation."}]

[{"index":"void DeleteAsync(string key, func callbackFunction) (ServerOnly)","0":"Deletes data with the entered keys. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code and key upon completion of the operation."}]

[{"index":"int32, string GetAndWait(string key) (ServerOnly) (Yield)","0":"Gets data. Returns the error code and data. Script executions are suspended during the operation."}]

[{"index":"void GetAsync(string key, func callbackFunction) (ServerOnly)","0":"Gets data. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code, key, and data upon completion of the operation."}]

[{"index":"int32, string GetByInfoAndWait(DataStorageKeyInfo keyInfo) (ServerOnly) (Yield)","0":"Queries data with the DataStorageKeyInfo entered. You can set the detailed conditions of data to be loaded with DataStorageKeyInfo. Returns the error code and data when the operation is complete. Script executions are suspended during the operation."}]

[{"index":"void GetByInfoAsync(DataStorageKeyInfo keyInfo, func callbackFunction) (ServerOnly)","0":"Queries data with the DataStorageKeyInfo entered. You can set the detailed conditions of data to be loaded with DataStorageKeyInfo. This operation is performed asynchronously. The function passed to the callbackFunction is called with the error code, DataStorageKeyInfo, and data when the operation is complete."}]

[{"index":"int32, DataStorageItemPages GetPagesAndWait(string tag) (ServerOnly) (Yield)","0":"Inquires about data that have the entered tags. You can see the inquiry result with the returned entity. Script executions are suspended during the operation."}]

[{"index":"void GetPagesAsync(string tag, func callbackFunction) (ServerOnly)","0":"Inquires about data that have the entered tags. You can see the inquiry result with the returned entity. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code, tag, and inquiry entity when completing the operation."}]

[{"index":"int32, DataStorageVersionPages GetVersionsAndWait(string key, SortDirection sortDirection, DateTime minDate, DateTime maxDate) (ServerOnly) (Yield)","0":"Queries the versions of data corresponding to the keys entered. Displays the inquiry results with the error code and inquiry entity. You can use sortDirection to sort in ascending or descending order. You can query the version created within the time zone set with minDate and maxDate. Suspends script executions during performance."}]

[{"index":"void GetVersionsAsync(string key, SortDirection sortDirection, DateTime minDate, DateTime maxDate, func callbackFunction) (ServerOnly)","0":"Queries the versions of data corresponding to the keys entered. You can use sortDirection to sort in ascending or descending order. You can query the version created within the time zone set with minDate and maxDate. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code, key, and inquiry entity when the operation is complete."}]

[{"index":"int32 SetAndWait(string key, string value) (ServerOnly) (Yield)","0":"Saves data and returns the error code. Script executions are suspended during the operation."}]

[{"index":"void SetAsync(string key, string value, func callbackFunction) (ServerOnly)","0":"Saves data. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code and key upon completion of the operation."}]

[{"index":"int32 SetByInfoAndWait(DataStorageKeyInfo keyInfo, string value) (ServerOnly) (Yield)","0":"Saves data with the DataStorageKeyInfo entered. You can set the detailed information with DataStorageKeyInfo. Returns the error code when the operation is complete. Script executions are suspended during the operation."}]

[{"index":"void SetByInfoAsync(DataStorageKeyInfo keyInfo, string value, func callbackFunction) (ServerOnly)","0":"Saves data with the DataStorageKeyInfo entered. You can set the detailed information with DataStorageKeyInfo. This operation is performed asynchronously, and the function passed to the callbackFunction is called with the error code and DataStorageKeyInfo when the operation is complete."}]

[{"index":"int32, List TransactDeleteAndWait(List keys) (ServerOnly) (Yield)","0":"Deletes data corresponding to the keys entered. Returns the keys that have been deleted along with the error code if all tasks within the call are successful. Script executions are suspended during operation. Function will not be called if any of the tasks fail. You can manipulate up to 20 keys at a time."}]

[{"index":"void TransactDeleteAsync(List keys, func> callbackFunction) (ServerOnly)","0":"Deletes data corresponding to the keys entered. This call is performed asynchronously. The function passed to the callbackFunction is called with the deleted keys and error code if all tasks within the call are successful. Function will not be called if any of the tasks fail. You can manipulate up to 20 keys at a time."}]

[{"index":"int32, List TransactSetAndWait(Dictionary keyValues) (ServerOnly) (Yield)","0":"Saves data corresponding to the keys entered. Returns the keys that have been saved along with the error code if all tasks within the call are successful. Script executions are suspended during operation. Function will not be called if any of the tasks fail. You can manipulate up to 20 keys at a time."}]

[{"index":"void TransactSetAsync(Dictionary keyValues, func> callbackFunction) (ServerOnly)","0":"Saves data corresponding to the keys entered. This call is performed asynchronously. The function passed to the callbackFunction is called with the saved keys and error code if all tasks within the call are successful. Function will not be called if any of the tasks fail. You can manipulate up to 20 keys at a time."}]

[{"index":"int32, List TransactSetByInfoAndWait(Dictionary keyValues) (ServerOnly) (Yield)","0":"Saves data with the entered DataStorageKeyInfo. Returns the DataStorageKeyInfo that succeeded and the error code if all data has been saved. Script executions are suspended during operation. Function will not be called if any of the tasks fail. You can manipulate up to 20 keys at a time."}]

[{"index":"void TransactSetByInfoAsync(Dictionary keyValues, func> callbackFunction) (ServerOnly)","0":"Saves data with the DataStorageKeyInfo entered. This call is performed asynchronously. The function passed to the callbackFunction is called with the error code and the saved DataStorageKeyInfo if all tasks within the call are successful. Function will not be called if any of the tasks fail. You can manipulate up to 20 keys at a time."}]

[{"index":"int32, string UpdateAndWait(string key, string expectedValue, string newValue) (ServerOnly) (Yield)","0":"Updates the corresponding key value to newValue. When the operation succeeds, it returns the error code and the updated value. If the previous value and expectedValue are different, it returns the error code UpdateApiFailed(2000000) and the previous value. Suspends script executions during performance."}]

[{"index":"void UpdateAsync(string key, string expectedValue, string newValue, func callbackFunction) (ServerOnly)","0":"Updates the corresponding key value to newValue. This operation is performed asynchronously. The function passed to the callbackFunction is called with the error code, key, and updated value when completing the operation. If the previous value and expectedValue are different, it delivers the error code UpdateApiFailed(2000000), key, and the previous value."}]

[{"index":"int32, string UpdateByInfoAndWait(DataStorageKeyInfo keyInfo, string expectedValue, string newValue) (ServerOnly) (Yield)","0":"Updates the DataStorageKeyInfo value to newValue. When the operation succeeds, it returns the error code and the updated value. If the previous value and expectedValue are different, the error code UpdateApiFailed(2000000) and the previous value are returned. Suspends script executions during performance."}]

[{"index":"void UpdateByInfoAsync(DataStorageKeyInfo keyInfo, string expectedValue, string newValue, func callbackFunction) (ServerOnly)","0":"Updates the DataStorageKeyInfo value to newValue. This operation is performed asynchronously. The function passed to the callbackFunction is called with the error code, DataStorageKeyInfo, and updated value when completing the operation. If the previous value and expectedValue are different, it delivers the error code UpdateApiFailed(2000000), DataStorageKeyInfo, and the previous value."}]

# Examples

#### SetAndWait

This is an example of saving data.
    
    
    @Component
    script GlobalDataInitializer extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local errorCode = ds:SetAndWait("key", "value")
        end
    end
    

#### GetAndWait

This is an example of loading data.
    
    
    @Component
    script GlobalDataRetriever extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local errorCode, value = ds:GetAndWait("key")
        end
    end
    

#### DeleteAndWait

This is an example of deleting data.
    
    
    @Component
    script DataKeyDeleter extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local errorCode = ds:DeleteAndWait("key")
        end
    end
    

#### SetAsync

This is an example of asynchronously saving data.
    
    
    @Component
    script GlobalDataSetter extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            ds:SetAsync("key", "value", function(errorCode, key)
                -- It will be called when the operation is completed.
            end)
        end
    end
    

#### GetAsync

This is an example of asynchronously loading data.
    
    
    @Component
    script GlobalDataFetcher extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            ds:GetAsync("key", function(errorCode, key, value)
                -- It will be called when the operation is completed.
            end)
        end
    end
    

#### DeleteAsync

This is an example of asynchronously deleting data.
    
    
    @Component
    script GlobalKeyDeleter extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            ds:DeleteAsync("Key", function(errorCode, key)
                -- It will be called when the operation is completed. 
            end)
        end
    end
    

#### SetByInfoAndWait

This is an example of saving data using DataStorageKeyInfo.
    
    
    @Component
    script StorageKeySetter extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keyInfo = DataStorageKeyInfo("Key", "Version1", "TestTag")
            local errorCode = ds:SetByInfoAndWait(keyInfo, "value")
        end
    end
    

#### GetByInfoAndWait

This is an example of loading data using DataStorageKeyInfo.
    
    
    @Component
    script GlobalDataFetcher extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keyInfo = DataStorageKeyInfo("Key", "Version1", "TestTag")
            local errorCode, value = ds:GetByInfoAndWait(keyInfo)
        end
    end
    

#### BatchByInfoAndWait

This is an example of saving data in bulk.
    
    
    @Component
    script BatchDataSetter extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keyValues = {}
            keyValues["Key1"] = "Value1"
            keyValues["Key2"] = "Value2"
            
            local errorCode, keys = ds:BatchSetAndWait(keyValues)lua
        end
    end
    

#### BatchGetAndWait

This is an example of loading data in bulk.
    
    
    @Component
    script BatchDataIterator extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keys = {}
            table.insert(keys, "Key1")
            table.insert(keys, "Key2")
            
            local errorCode, itemPages = ds:BatchGetAndWait(keys)
            
            while true do
                -- You can get a list of current pages with GetCurrentPageDatas().
                local items = itemPages:GetCurrentPageDatas()
                for _, item in pairs(items) do
            
                    -- You can lookup the Key and Value values using DataStorageItem.
                    log(item.KeyInfo.Key)
                    log(item.KeyInfo.Tag)
                    log(item.KeyInfo.Version)
                    log(item.Value)
                end
            
                -- You can check if the current page is the last page using the IsLastPage property.
                if itemPages.IsLastPage == true then
                    break
                end
            
                -- You can move to the next page using MoveToNextPageAndWait().
                itemPages:MoveToNextPageAndWait()
            end
        end
    end
    

#### BatchDeleteAndWait

This is an example of deleting data in bulk.
    
    
    @Component
    script BatchDataDeleter extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keys = {}
            table.insert(keys, "Key1")
            table.insert(keys, "Key2")
            
            local errorCode, deletedKeys = ds:BatchDeleteAndWait(keys)
        end
    end
    

#### BatchSetByInfoAndWait

This is an example of saving data in bulk using DataStorageKeyInfo.
    
    
    @Component
    script DataStorageInitializer extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keyInfoValues = {}
            local keyInfo1 = DataStorageKeyInfo("Key1", "Version1", "Tag1")
            local keyInfo2 = DataStorageKeyInfo("Key2", "Version2", "Tag2")
            
            keyInfoValues[keyInfo1] = "Value1"
            keyInfoValues[keyInfo2] = "Value2"
            
            local errorCode, keyInfos = ds:BatchSetByInfoAndWait(keyInfoValues)
        end
    end
    

#### BatchGetByInfoAndWait

This is an example of loading data in bulk using DataStorageKeyInfo.
    
    
    @Component
    script DataStorageBatchPageFetcher extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keyInfos = {}
            local keyInfo1 = DataStorageKeyInfo("Key1", "Version1", "Tag1")
            local keyInfo2 = DataStorageKeyInfo("Key2", "Version2", "Tag2")
            table.insert(keyInfos, keyInfo1)
            table.insert(keyInfos, keyInfo2)
            
            local errorCode, itemPages = ds:BatchGetByInfoAndWait(keyInfos)
            
            while true do
                -- You can get a list of current pages with GetCurrentPageDatas().
                local items = itemPages:GetCurrentPageDatas()
                for _, item in pairs(items) do
            
                    -- You can lookup the Key and Value values using DataStorageItem.
                    log(item.KeyInfo.Key)
                    log(item.KeyInfo.Tag)
                    log(item.KeyInfo.Version)
                    log(item.Value)
                end
            
                -- You can check if the current page is the last page using the IsLastPage property.
                if itemPages.IsLastPage == true then
                    break
                end
            
                -- You can move to the next page using MoveToNextPageAndWait().
                itemPages:MoveToNextPageAndWait()
            end
        end
    end
    

#### GetPagesAndWait

This is an example of looking up data using a tag value.
    
    
    @Component
    script PagedDataReader extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local errorCode, itemPages = ds:GetPagesAndWait("TestTag")
            
            while true do
                -- You can get a list of current pages with GetCurrentPageDatas().
                local items = itemPages:GetCurrentPageDatas()
                for _, item in pairs(items) do
            
                    -- You can lookup the Key and Value values using DataStorageItem.
                    log(item.KeyInfo.Key)
                    log(item.KeyInfo.Tag)
                    log(item.KeyInfo.Version)
                    log(item.Value)
                end
            
                -- You can check if the current page is the last page using the IsLastPage property.
                if itemPages.IsLastPage == true then
                    break
                end
            
                -- You can move to the next page using MoveToNextPageAndWait().
                itemPages:MoveToNextPageAndWait()
            end
        end
    end
    

#### GetVersionsAndWait

This is an example of looking up version information within a specific time period.
    
    
    @Component
    script DataVersionRetriever extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local minDate = DateTime(2023, 03, 09, 20, 20, 0, 0)
            local maxDate = DateTime(2023, 03, 09, 22, 20, 0, 0)
            
            -- You can only look up the value if the version value was specified when saving it.
            local errorCode, versionPages = ds:GetVersionsAndWait("Key", SortDirection.Ascending, minDate, maxDate)
            
            while true do
                -- You can get a list of current pages with GetCurrentPageDatas().
                local versions = versionPages:GetCurrentPageDatas()
                for _, version in pairs(versions) do
                    -- You can lookup the creation time and version value using DataStorageVersionInfo.
                    log(version.CreateTime)
                    log(version.Version)
                end
            
                -- You can check if the current page is the last page using the IsLastPage property.
                if versionPages.IsLastPage == true then
                    break
                end
            
                -- You can move to the next page using MoveToNextPageAndWait().
                versionPages:MoveToNextPageAndWait()
            end
        end
    end
    

#### GetAndWait

This is an example of updating data.
    
    
    @Component
    script ConditionalDataUpdater extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local errorCode, oldValue = ds:GetAndWait("Key")
            if errorCode ~= 0 then
                log("failed")
                return
            end
            
            -- If the expected value is saved in DataStorage, saves "NewValue". If a different value is saved, it will fail.
            local errorCode2, newValue = ds:UpdateAndWait("Key", oldValue, "NewValue")
        end
    end
    

#### Utilizing Versions

This is an example of utilizing versions.
    
    
    @Component
    script DataVersionManager extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local ds = _DataStorageService:GetGlobalDataStorage("StorageName")
            
            local keyInfo = DataStorageKeyInfo()
            keyInfo.Key = "Key"
            keyInfo.Version = "Version1"
            
            ds:SetByInfoAndWait(keyInfo, "Value")
            
            -- Instead of overwriting the value of Value in the existing version, create a new version and save it.
            keyInfo.Key = "Key"
            keyInfo.Version = "Version2"
            ds:SetByInfoAndWait(keyInfo, "Value2")
            
            -- The value of Value is still valid, since it has not been overwritten, and you can retrieve the value of Value1 by specifying Version1.
            keyInfo.Key = "Key"
            keyInfo.Version = "Version1"
            local errorCode, oldValue = ds:GetByInfoAndWait(keyInfo)
            
            -- Retrieve the value from a previous version and overwrite it in the latest version. When you call the GetAndWait function afterwards, it will return the value of Value instead of Value2.
            keyInfo.Key = "Key"
            keyInfo.Version = "Version2"
            ds:SetByInfoAndWait(keyInfo, oldValue)
        end
    end
    

# SeeAlso

  * table
  * DataStorageKeyInfo
  * DateTime
  * DataStorageService
  * [Learning DataStorage Use Limits](/docs?postId=1044)
  * [Saving and Importing Data DB](/docs?postId=68)
  * [Utilizing DataStorage](/docs?postId=692)
  * [Utilizing DataStorage Use Limits](/docs?postId=1045)