Skip to main content
Version: 6.0.0

Implementing Game Information Editing

1. Write a game information edit method

Add content to the LevelUp and PlayerTableUpdate methods in BackndGameData.cs written in Pre-arrangements.

BackndGameData.cs

Before editing

    public void LevelUp() {
// Step 4. Implementing Game Information Editing
}

public void PlayerTableUpdate() {
// Step 4. Implementing Game Information Editing
}

After editing

    public void LevelUp() {
Debug.Log("Increases the level by 1.");
userData.level += 1;
userData.atk += 3.5f;
userData.info = "Changes details.";
}

// Edit game information
public void PlayerTableUpdate() {
if(userData == null) {
Debug.LogError("Data downloaded from the server or newly inserted data does not exist. Use "Insert" or "Get" to create data.");
return;
}

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);

BackndReturnObject bro = null;

if(string.IsNullOrEmpty(gameDataRowInDate)) {
Debug.Log("Requests my latest game information data to be edited.");

bro = Backnd.PlayerTable.UpdateMyLatestData("USER_DATA", param);
} else {
Debug.Log($"Requests {gameDataRowInDate} to be edited.");

bro = Backnd.PlayerTable.UpdateMyLatestData("USER_DATA", param);
}

if(bro.IsSuccess()) {
Debug.Log("Successfully edited game information data. : " + bro);
} else {
Debug.LogError("Failed to edit game information data. : " + 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(After Step 3. Game Information Loading)

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

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

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

After editing

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

BackndGameData.Instance.PlayerTableGet(); // Data insertion method

// [Addition] When the loaded data from the server does not exist, new data is created and inserted
if(BackndGameData.userData == null) {
BackndGameData.Instance.PlayerTableInsert();
}

BackndGameData.Instance.LevelUp(); // [Addition] Locally saved data is changed

BackndGameData.Instance.PlayerTableUpdate(); //[Addition] Overwrites data saved in the server(only parts that have changed)

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

3. Test in Unity

After editing the script, execute Unity debugging and check the console log of Unity.

The process has been successfully completed when the log displays 'Requesting my latest game information data to be edited : statusCode : 204'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which error caused the failure in Update error case.

4. Check in the console

When a log on success appears on the Unity console, go to BACKND Console and check BACKND Base > Game Information Management > Data to confirm that the row has been changed.
The value increases every time the method is called; therefore, it may differ from the value in the example below.