Hi so I've made a request in Unity C# : GetTimeRequest time = new GetTimeRequest();.
How do I get the time value stored in the time variable?
Hi so I've made a request in Unity C# : GetTimeRequest time = new GetTimeRequest();.
How do I get the time value stored in the time variable?
Hi Alen.
You can try this out, where a function calls a new GetTimeRequest, then calls another function (passing in the result) when it succeeds. A third function is written to catch any errors.
void GetCurrentTime() { PlayFabServerAPI.GetTime(new GetTimeRequest(), OnGetTimeSuccess, LogFailure); }
void OnGetTimeSuccess(GetTimeResult result) { Debug.Log("The time is: " + result.Time); }
void LogFailure(PlayFabError error) { Debug.Log("There was a problem getting the time. Error: " + error.GenerateErrorReport()); }
GetTimeResult time = new GetTimeResult(); will only make a new, blank instance of a GetTimeResult (which is why it gave you 01-01-0001 00:00:00);
Hope this helps! Let me know if you have any other questions.
I'm on the free tier of playfab. So can I make this call every second? Assuming we get a good number of players will this lead to a throttle?
I typically would not recommend making any calls that often if it could be avoided. Is there a particular reason you need it to be every second?
If you are wanting to display the time, you could get the server time once and start a clock function on the client side that uses system time. You could also check in with the server every other minute (for example) to ensure that the client and server times are in sync.
In the cloudscript example, there is this:
server.UpdatePlayerStatistics(request); server.UpdateUserInternalData({ PlayFabId: currentPlayerId, Data: { last_move_timestamp: new Date(now).toUTCString(), last_move: JSON.stringify(playerMove) } });
if I am similarly using cloudscript to do a function with time, can I just use the Date(now).toUTCString() function as opposed to doing a server.GetTimeRequest()?
4 People are following this question.