I want to avoid that a player can call server.UpdateUserInternalData and server.GetUserReadOnlyData very frequently. Therefore I want to save the timestamp of the last server.UpdateUserInternalData call in UserInternalData and the timestamp of the last server.GetUserReadOnlyData call in UserReadOnlyData.
For example, the player calls the cloud script function Function1 that uses server.UpdateUserInternalData API. I just want to update "PlayerData1": newdata if the last server.UpdateUserInternalData call was at least 4 seconds before the current time(currenttimeinseconds). But I don't know what I should do if the last update call was not at least 4 seconds before the current time(currenttimeinseconds).
Is it possible to wait in Function1 until ((Number(playertimestamp) + 4) < Number(currenttimeinseconds)) is true and then continue normally with updating "PlayerData1": newdata ? How can I do that? How can I wait in Function1?
Or is it better to quit Function1 without updating anything and then the client needs to call ExecuteCloudScript(Function1) again so that "PlayerData1": newdata can maybe be updated?
function Function1(string newdata) { var playertimestamp = GetTimestampInternalData(); var currenttimeinseconds = getServerTimestamp(); if ((Number(playertimestamp) + 4) < Number(currenttimeinseconds)) { server.UpdateUserInternalData({ PlayFabId: currentPlayerId, Data: { "PlayerData1": newdata }, Permission: UserDataPermission.Private }); var timestampinseconds = getServerTimestamp(); CreateTimestampInternalData(timestampinseconds); } else { // Is it possible to wait here until ((Number(playertimestamp) + 4) < Number(currenttimeinseconds)) is true and then continue normally with updating "PlayerData1": newdata ? } } function GetTimestampInternalData() { var resultdata = server.GetUserInternalData({PlayFabId: currentPlayerId, Keys: "InternalDataTimestamp"}); var currenttimestamp = ""; if ((resultdata.Data.hasOwnProperty("InternalDataTimestamp")) && (resultdata.Data.InternalDataTimestamp.Value != null) && (resultdata.Data.InternalDataTimestamp.Value != "")) currenttimestamp = resultdata.Data.InternalDataTimestamp.Value; else currenttimestamp = 0; return currenttimestamp; } function CreateTimestampInternalData(currenttime) { server.UpdateUserInternalData({ PlayFabId: currentPlayerId, Data: { "InternalDataTimestamp": currenttime.toString() }, Permission: UserDataPermission.Private }); } function getServerTimestamp() { var now = new Date(); var time = now.getTime(); time = Math.floor(time / 1000); return time; }