Skip to content

Instantly share code, notes, and snippets.

@PLyczkowski
Last active September 19, 2018 20:29
Show Gist options
  • Save PLyczkowski/a0ed9c7faee74494f876f47ebec89e34 to your computer and use it in GitHub Desktop.
Save PLyczkowski/a0ed9c7faee74494f876f47ebec89e34 to your computer and use it in GitHub Desktop.
using Godot;
using System;
using System.Runtime;
using System.Threading;
using System.Threading.Tasks;
using PlayFab;
using PlayFab.ClientModels;
public class Main : Node
{
private static bool _running = true;
public override void _Ready()
{
PlayFabSettings.TitleId = "258B"; // Please change this value to your own titleId from PlayFab Game Manager
var request = new LoginWithCustomIDRequest{ CustomId = "GettingStartedGuide", CreateAccount = true };
var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(request);
// If you want a synchronous ressult, you can call loginTask.Wait() - Note, this will halt the program until the function returns
while (_running)
{
if (loginTask.IsCompleted) // You would probably want a more sophisticated way of tracking pending async API calls in a real game
{
OnLoginComplete(loginTask);
}
// Presumably this would be your main game loop, doing other things
// System.Threading.Thread.Sleep(1);
}
GD.Print("Done! Press any key to close");
}
private static void OnLoginComplete(Task<PlayFabResult<LoginResult>> taskResult)
{
var apiError = taskResult.Result.Error;
var apiResult = taskResult.Result.Result;
if (apiError != null)
{
GD.Print("Something went wrong with your first API call. :(");
GD.Print("Here's some debug information:");
GD.Print(PlayFabUtil.GenerateErrorReport(apiError));
}
else if (apiResult != null)
{
GD.Print("Congratulations, you made your first successful API call!");
}
_running = false; // Because this is just an example, successful login triggers the end of the program
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment