question

youssefkream36 avatar image
youssefkream36 asked

UpdateUserDataRequest PlayPapID Error CS0117

I am working on a login system on Unity, but I encountered a problem that two people could enter the same account and play in it, so I used the LockAccount method, but I encountered errors such as Error CS0117 'UpdateUserDataRequest' does not contain a definition for 'PlayFabId' and Error CS0103 The name 'OnGetUserDataError' does not exist in the current context , and this is the code that contains revision errors.

 using PlayFab;
 using PlayFab.ClientModels;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
    
     public InputField EmailInputFeild;
     public InputField PasswordInputFeild;
     public InputField email;
     public Text Mess;
    
 public class PlayFabManager : MonoBehaviour
 {
    
    
     public void Login()
     {
         string username = EmailInputFeild.text;
         string password = PasswordInputFeild.text;
    
         var request = new LoginWithEmailAddressRequest
         {
             Email = username,
             Password = password
         };
    
         PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginError);
     }
    
     private void OnLoginSuccess(LoginResult result)
     {
         string playerId = result.PlayFabId;
         Debug.Log("Login successful! Player ID: " + playerId);
    
         CheckAccountStatus(playerId);
     }
    
     private void OnLoginError(PlayFabError error)
     {
         Debug.LogError("Login failed: " + error.GenerateErrorReport());
     }
    
     private void CheckAccountStatus(string playerId)
     {
         PlayFabClientAPI.GetUserData(new GetUserDataRequest
         {
             PlayFabId = playerId,
             Keys = new List<string> { "AccountStatus" }
         }, result =>
         {
             if (result.Data.TryGetValue("AccountStatus", out UserDataRecord userDataRecord))
             {
                 string accountStatus = userDataRecord.Value;
                 if (accountStatus == "locked")
                 {
                     Debug.Log("Account is already locked. Cannot log in from another device.");
                     
                     Mess.text = "Account is already locked. Cannot log in from another device.";
                 }
                 else
                 {
                     Debug.Log("Account is not locked. Proceed with login.");
                      
                     LockAccount(playerId);
                      
                     Mess.text = "Login successful!";
                 }
             }
             else
             {
                 Debug.Log("AccountStatus not found in player's data. Proceed with login.");
                   
                 LockAccount(playerId);
                   
                 Mess.text = "Login successful!";
             }
         }, OnGetUserDataError /*error 2 : Error CS0103*/);
     }
    
     private void LockAccount(string playerId)
     {
         var updatedData = new Dictionary<string, string>
         {
             { "AccountStatus", "locked" }
         };
    
         var request = new UpdateUserDataRequest
         {
             PlayFabId = playerId, /*error 1 : ErrorCS0117 */
             Data = updatedData
         };
    
         PlayFabClientAPI.UpdateUserData(request, OnUpdateUserDataSuccess, OnUpdateUserDataError);
     }
    
     private void OnUpdateUserDataSuccess(UpdateUserDataResult result)
     {
         Debug.Log("Account locked successfully!");
     }
    
     private void OnUpdateUserDataError(PlayFabError error)
     {
         Debug.LogError("Failed to lock account: " + error.GenerateErrorReport());
         Mess.text = "Failed to lock account. Please try again.";
     }
 }
community
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Neils Shi avatar image
Neils Shi answered

The Client API UpdateUserData does not require you to specify “PlayFabId” in the request, It will create/update the data for the currently logged in player. That's why you received the error message: " CS0117 'UpdateUserDataRequest' does not contain a definition for 'PlayFabId'". And the error “CS0103 The name 'OnGetUserDataError' does not exist in the current context” means you used a method which does not exist in the current context. To fix this error, you need to implement the method 'OnGetUserDataError' yourself.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.