I'm new to Gamesparks but i already like it, good job. Btw I've a problem that I can't figure out how to solve. Basically I'm trying to authenticate my user, so I've this `EmptyGameObject` to which i linked the GameSparksManager.cs that inside has this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameSparksManager : MonoBehaviour {
private static GameSparksManager instance = null;
void Awake()
{
if (instance == null) {
instance = this;
DontDestroyOnLoad (this.gameObject);
} else {
Destroy (this.gameObject);
}
}
}
Then i made a form where i'm trying to login my user and on submit it runs this code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using GameSparks.Core;
public class AuthenticatePlayer : MonoBehaviour {
public Text
userNameInput,
passwordInput;
public void AuthenticatePlayerButton()
{
Debug.Log (GS.Available);
Debug.Log ("Authenticating User");
new GameSparks.Api.Requests.AuthenticationRequest()
.SetUserName(userNameInput.text)
.SetPassword(passwordInput.text)
.Send((response) => {
if(response.HasErrors)
{
Debug.Log("Error while authenticating player \nuser: " + response.DisplayName);
}
else
{
Debug.Log("User authenticated \n" + response.Errors.JSON.ToString());
}
});
}
}
As you can see i'm checking if i'm connected to GS and it returns `true` but i get this error:
Anyone have an idea on what i'm doing wrong??
Login and Registration are on the same scene but registration works and login not.
Best Answer
C
Customer Support
said
over 5 years ago
Hey there!
The null reference you are getting is being caused by your response logic.
if(response.HasErrors)//If you have an Error
{
//Do this.....
Debug.Log("Error while authenticating player \nuser: "+ response.DisplayName);}else //if you dont have an error
{
//Do this.....
Debug.Log("User authenticated \n"+ response.Errors.JSON.ToString());}
In your else ( no errors) you are looking for errors that do not exist(Null reference). You can correct this by using !response.HasErrors.
Regards, -Dave
1 Comment
Customer Support
said
over 5 years ago
Answer
Hey there!
The null reference you are getting is being caused by your response logic.
if(response.HasErrors)//If you have an Error
{
//Do this.....
Debug.Log("Error while authenticating player \nuser: "+ response.DisplayName);}else //if you dont have an error
{
//Do this.....
Debug.Log("User authenticated \n"+ response.Errors.JSON.ToString());}
In your else ( no errors) you are looking for errors that do not exist(Null reference). You can correct this by using !response.HasErrors.
Stefano Cerelli
Btw I've a problem that I can't figure out how to solve.
Basically I'm trying to authenticate my user, so I've this `EmptyGameObject` to which i linked the GameSparksManager.cs that inside has this code:
Then i made a form where i'm trying to login my user and on submit it runs this code:
As you can see i'm checking if i'm connected to GS and it returns `true` but i get this error:
Anyone have an idea on what i'm doing wrong??
Login and Registration are on the same scene but registration works and login not.
The null reference you are getting is being caused by your response logic.
In your else ( no errors) you are looking for errors that do not exist(Null reference). You can correct this by using !response.HasErrors.
Regards,
-Dave
Customer Support
The null reference you are getting is being caused by your response logic.
In your else ( no errors) you are looking for errors that do not exist(Null reference). You can correct this by using !response.HasErrors.
Regards,
-Dave
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics