Search Unity

Help with PlayFab Login Script

Discussion in 'Scripting' started by Porras3009, Jan 18, 2022.

  1. Porras3009

    Porras3009

    Joined:
    Jan 16, 2022
    Posts:
    2
    I have the following error: error CS1503: Argument 3: cannot convert from 'method group' to 'Action<PlayFabError>'. Line (60,69). I'm new to this and I have been trying but I can't fix it. If anyone can help, please.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using PlayFab;
    6. using PlayFab.ClientModels;
    7.  
    8. public class PlayfabControl : MonoBehaviour
    9. {
    10.    
    11.     [SerializeField] GameObject singUpTab, logInTab, startPanel, HUD;
    12.     public Text username, userEmail, userPassword, userEmailLogin, userPasswordLogin, errorSingUp, errorLogIn;
    13.     string encryptedPassword;
    14.  
    15.     public void SwichToSingUpTab(){
    16.       singUpTab.SetActive(true);
    17.       logInTab.SetActive(false);
    18.        errorSingUp.text = "";
    19.        errorLogIn.text = "";
    20.     }
    21.  
    22.     public void SwichToLoginTab(){
    23.        singUpTab.SetActive(false);
    24.        logInTab.SetActive(true);
    25.        errorSingUp.text = "";
    26.        errorLogIn.text = "";
    27.     }
    28.  
    29.  
    30.     string Encrypt(string pass){
    31.       System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
    32.       byte[] bs = System.Text.Encoding.UTF8.GetBytes(pass);
    33.       bs = x.ComputeHash(bs);
    34.       System.Text.StringBuilder s = new System.Text.StringBuilder();
    35.       foreach(byte b in bs){
    36.         s.Append(b.ToString("x2").ToLower());
    37.       }
    38.       return s.ToString();
    39.     }
    40.      
    41.   public void SingUp(){
    42.     var registerRequest = new RegisterPlayFabUserRequest{Email = userEmail.text, Password = Encrypt(userPassword.text), Username = username.text};
    43.     PlayFabClientAPI.RegisterPlayFabUser(registerRequest, RegisterSuccess, RegisterError);
    44.   }
    45.  
    46.  
    47.  
    48.   public void RegisterSuccess(RegisterPlayFabUserResult result){
    49.     errorSingUp.text = "";
    50.     errorLogIn.text = "";
    51.     StartGame();
    52.   }
    53.  
    54.   public void RegisterError(PlayFabError error){
    55.     errorSingUp.text = error.GenerateErrorReport();
    56.   }
    57.  
    58.   public void LoginIn(){
    59.     var request = new LoginWithEmailAddressRequest {Email = userEmailLogin.text, Password = Encrypt(userPasswordLogin.text)};
    60.     PlayFabClientAPI.LoginWithEmailAddress(request, LoginInSuccess, LoginInSuccess);
    61.   }
    62.  
    63.  
    64.   public void LoginInSuccess(LoginResult result){
    65.     errorSingUp.text = "";
    66.     errorLogIn.text = "";
    67.     StartGame();
    68.   }
    69.  
    70.  
    71.   public void LogInError(PlayFabError error){
    72.     errorLogIn.text = error.GenerateErrorReport();
    73.   }
    74.  
    75.   void StartGame(){
    76.     startPanel.SetActive(false);
    77.     HUD.SetActive(true);
    78.   }
    79.  
    80. }
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    I know nothing about Playfab but the error is telling you that you're passing the name of a method (LogInSuccess) when it's expecting "Action<PlayFabError>". Those two are nothing to do with each other.

    Maybe this will help: https://answers.unity.com/questions/638667/how-to-pass-values-through-action.html

    The action needs to be assigned to some method (delegate). You can then pass the action to that call by the looks of it.
     
    Porras3009 likes this.
  3. Porras3009

    Porras3009

    Joined:
    Jan 16, 2022
    Posts:
    2
    Thank you, it was LogInError instead of LoginSucces. Anyway now it compiles without errors, but the scrip itself doesn't work I don't know why.