Skip to main content
Version: 6.0.0

Implementing Game Information Loading

1. Write a game information loading method

Add content to the PlayerTableGet method in BackndGameData.cs written in Pre-arrangements.

BackndGameData.cs

Before editing

    public void PlayerTableGet() {
// Step 3. Implementing Game Information Loading
}

After editing

    public void PlayerTableGet() {
Debug.Log("Calls the game information lookup method.");
var bro = Backnd.PlayerTable.GetMyData("USER_DATA");
if(bro.IsSuccess()) {
Debug.Log("Game information lookup successful. : " + bro);


BACKND.LitJson.JsonData gameDataJson = bro.FlattenRows(); // Receives data returned in JSON format.

// If the number of returned data cases is 0, the data does not exist.
if(gameDataJson.Count <= 0) {
Debug.LogWarning("The data does not exist.");
} else {
gameDataRowInDate = gameDataJson[0]["inDate"].ToString(); //This is the unique value of the loaded game information.

userData = new UserData();

userData.level = int.Parse(gameDataJson[0]["level"].ToString());
userData.atk = float.Parse(gameDataJson[0]["atk"].ToString());
userData.info = gameDataJson[0]["info"].ToString();

foreach(string itemKey in gameDataJson[0]["inventory"].Keys) {
userData.inventory.Add(itemKey, int.Parse(gameDataJson[0]["inventory"][itemKey].ToString()));
}

foreach(BACKND.LitJson.JsonData equip in gameDataJson[0]["equipment"]) {
userData.equipment.Add(equip.ToString());
}

Debug.Log(userData.ToString());
}
} else {
Debug.LogError("Failed to look up game information. : " + bro);
}
}

2. Add method call to BackndManager.cs

BackndManager, which is automatically called when the game is executed, must be used to call this method.
Add it so that the method may be called after BACKND initialization and BACKND login.

BackndManager.cs

Before editing(Step 2. Implementing Game Information Insertion)

    async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1","1234"); // BACKND login

BackndGameData.Instance.PlayerTableInsert(); //[Addition] Data insertion method

Debug.Log("Test complete.");
});
}

After editing

    async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1", "1234"); // BACKND login

BackndGameData.Instance.PlayerTableGet(); //[Addition] Data loading method

Debug.Log("Test complete.");
});
}

3. Test in Unity

After editing the script, execute Unity debugging and check the console log of Unity.
Check that the logs for each parsed data are being printed correctly.

The method has been successfully called when the log displays the item names properly.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which error caused the failure in GetMyData error case.