insert
BACKND Guidelines > 2. Implementing Game Information Functions > Step 2. Implementing Game Information Insertion
Implementing Game Information Insertion
1. Write a game information insertion method
Add content to the GameDataInsert method in BackendGameData.cs written in Pre-arrangements.
BackendGameData.cs
Before editing
public void GameDataInsert() {
// Step 2. Implementing Game Information Insertion
}
After editing
public void GameDataInsert() {
if(userData == null) {
userData = new UserData();
}
Debug.Log("Resets data.");
userData.level = 1;
userData.atk = 3.5f;
userData.info = "Adding friends is always welcome.";
userData.equipment.Add("Warrior's Helm");
userData.equipment.Add("Steel Armor");
userData.equipment.Add("Hermes Military Boots");
userData.inventory.Add("Red Potion", 1);
userData.inventory.Add("White Potion", 1);
userData.inventory.Add("Blue Potion", 1);
Debug.Log("Adds these pieces of data to the BACKND update list.");
Param param = new Param();
param.Add("level", userData.level);
param.Add("atk", userData.atk);
param.Add("info", userData.info);
param.Add("equipment", userData.equipment);
param.Add("inventory", userData.inventory);
Debug.Log("Requests the insertion of game information data.");
var bro = Backend.GameData.Insert("USER_DATA", param);
if(bro.IsSuccess()) {
Debug.Log("Successfully inserted game information data. : " + bro);
//This is the unique value for the inserted game information.
gameDataRowInDate = bro.GetInDate();
} else {
Debug.LogError("Failed to insert game information data. : " + bro);
}
}
2. Add method call to BackendManager.cs
BackendManager, 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.
BackendManager.cs
Before editing
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1","1234"); // BACKND login
// Adds a logic to implement the game information function
Debug.Log("Test complete.");
});
}
After editing
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234"); // BACKND login
BackendGameData.Instance.GameDataInsert(); //[Addition] Data insertion method
Debug.Log("Test complete.");
});
}
3. Test in Unity
After editing the script, execute Unity debugging and check the console log of Unity.
The method has been successfully called when the log displays 'Game information insertion successful. : statusCode : 200'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which error caused the failure in Insertion error case.
When statusCode : 404 error occurs
When Failed to insert game information data : statusCode 404 table not found occurs, check that the name of the table set in Step 1. Pre-arrangements matches "USER_DATA" where the following code is entered. If they are different, keep them under the same name.
var bro = Backend.GameData.Insert("USER_DATA", param);
4. Check in the console
When a log on the success appears on the Unity console, go to BACKND Console and check Game Information Management > Data
to confirm that the user has been created.