So I have noticed a bug(Probably with my code not gamesparks) where you can post score to server perfectly first time after creating account however if you then sign into that account again or another previously created account the score doesnt post which I don't understand as its the same function for posting code for a new player as previously created players and non of my debug stuff is showing any errors.
Best Answer
W
Will Brett
said
over 7 years ago
Pretty certain its working in test harness. Just posted 3 scores and all could be found in the leaderboards. I think I may have found the culprit in my unity code. Im using the same function for when I login as the one I use to check if player high score.
public void FindHighScore()
{
//the leaderboard entries could contain old data.
//First destroy all existing Leaderboard objects
for (int i = 0; i < entries.Count; i++)
{
Destroy(entries[i]);
}
//because we deleted the objects contained on the list, the list //now contains nul references and has to be cleared so the new
//high score objects can be added
entries.Clear();
new AroundMeLeaderboardRequest_highScoreLeaderboard().SetEntryCount(1).Send((response) => {
//what we will do with the information given by GameSparks
foreach (var entry in response.Data)
{
string serverName = entry.UserName.ToString();
string playerName = PlayerPrefs.GetString("PlayerName");
if(serverName == playerName)
{
string playerScore = entry.GetNumberValue("score").ToString();
Debug.Log("PlayerFound " + playerName + "HighScore " + playerScore);
PlayerPrefs.SetString("OldHighScore", playerScore);
}
}
});
}
So going to change this and see if that solves the issue.
Think the issue is in this script as the create profile and login scripts are identical:
using UnityEngine;
using System.Collections;
using GameSparks.Api.Requests;
public class APIManager : MonoBehaviour {
public MenuManager menuMan;
public GetLeaderboardScore getScore;
void Awake()
{
bool nameOk = false;
bool passOk = false;
string pName = PlayerPrefs.GetString("PlayerName");
string pKey = PlayerPrefs.GetString("PlayerKey");
//Check if User has previously logged in or created an account
//Check Username
if(string.IsNullOrEmpty(pName))
{
Debug.Log ("Auto Login Name Error");
nameOk = false;
}
else
{
Debug.Log ("Auto Login Name Success. Name =: " + pName);
nameOk = true;
}
//Check Password
if(string.IsNullOrEmpty(pKey))
{
Debug.Log ("Auto Login Pass Error. Key =: ");
passOk = false;
}
else
{
Debug.Log ("Auto Login Pass success" + pKey);
passOk = true;
}
//Check bools are true for auto login
if(nameOk == true && passOk == true)
{
AutoLogin(pName, pKey);
}
}
void AutoLogin(string userName, string password)
{
//Show Auto Login panel
menuMan.ShowAutoLogin();
//Check Account details
new AuthenticationRequest().SetUserName(userName).SetPassword(password).Send((response) =>
{
if (response.HasErrors)
{
Debug.Log("Unable to autologin");
//Hide auto login panel
menuMan.HideAutoLogin();
//**SHOW AUTO LOGIN ERROR POPUP**
menuMan.ShowAutoLoginErrorPopup();
}
else
{
Debug.Log("Successfully Auto Logged in as " + userName);
//Hide auto login panel
menuMan.HideAutoLogin();
//Get score
getScore.FindHighScore();
//Show Ok Popup
menuMan.ShowAutoLoginSuccessPopup();
}
});
}
public void CreateProfile(string userName, string password, string displayName)
{
//Create account here
new RegistrationRequest().SetUserName(userName).SetPassword(password).SetDisplayName(displayName).Send((response) =>
{
if (response.HasErrors)
{
Debug.Log("Something failed with connecting with Username");
//** SHOW ERROR POPUP HERE**
menuMan.ShowErrorPopup();
}
else
{
Debug.Log("Successfully Created profile as " + userName);
//Here you can display some information
//to the user that they are logged in...
//SET USER INFO FOR AUTOLOGIN
PlayerPrefs.SetString("PlayerName", userName);
PlayerPrefs.SetString("PlayerKey", password);
//Get Old Highscore to 0 on new account
getScore.NewAccount();
//Show ok popup
menuMan.ShowSuccessPopup();
//Show Menu
//menuMan.ShowMenu();
//Hide SignUp
menuMan.HideSignup();
}
});
}
public void Login(string userName, string password)
{
//Check Account details
new AuthenticationRequest().SetUserName(userName).SetPassword(password).Send((response) =>
{
if (response.HasErrors)
{
Debug.Log("Something failed with connecting with Username");
//** SHOW ERROR POPUP HERE**
menuMan.ShowErrorPopup();
}
else
{
Debug.Log("Successfully Created profileas " + userName);
//Here you can display some information
//to the user that they are logged in...
//SET USER INFO FOR AUTOLOGIN
PlayerPrefs.SetString("PlayerName", userName);
PlayerPrefs.SetString("PlayerKey", password);
//Get score
getScore.FindHighScore();
//Show Ok Popup
menuMan.ShowSuccessPopup();
//Show Menu
//menuMan.ShowMenu();
//Hide Login
menuMan.HideLogin();
}
});
}
}
I
Irakli Geleishvili
said
over 7 years ago
I had error looking something similar. The scores weren't recorded after first try. Than I spotted that the scores lower than previous were recorded. The reason was - I had selected MINIMUM. In my case correct value was MAXIMUM.
I
Irakli Geleishvili
said
over 7 years ago
Sorry, I should make it more clear: You can switch to MAXIUM from Events screen > Edit Event > Attributes > Default Calc
W
Will Brett
said
over 7 years ago
thanks but mine is def set to maximum and its works when you first create an account but then logging back in or logging into another previously made account doesnt post a score
Customer Support
said
over 7 years ago
Hi Will,
Have you tested this in the Test Harness ? It's always good practice to test everything there first, this way you'll know everything is working properly and if you get an error in Unity, it's probably something in your code. Are you getting any errors in the Unity console ? If you could post up a screenshot of your leaderboard configuration and any events connected to it we should be able to get it sorted for you
Thanks,
Liam
W
Will Brett
said
over 7 years ago
Answer
Pretty certain its working in test harness. Just posted 3 scores and all could be found in the leaderboards. I think I may have found the culprit in my unity code. Im using the same function for when I login as the one I use to check if player high score.
public void FindHighScore()
{
//the leaderboard entries could contain old data.
//First destroy all existing Leaderboard objects
for (int i = 0; i < entries.Count; i++)
{
Destroy(entries[i]);
}
//because we deleted the objects contained on the list, the list //now contains nul references and has to be cleared so the new
//high score objects can be added
entries.Clear();
new AroundMeLeaderboardRequest_highScoreLeaderboard().SetEntryCount(1).Send((response) => {
//what we will do with the information given by GameSparks
foreach (var entry in response.Data)
{
string serverName = entry.UserName.ToString();
string playerName = PlayerPrefs.GetString("PlayerName");
if(serverName == playerName)
{
string playerScore = entry.GetNumberValue("score").ToString();
Debug.Log("PlayerFound " + playerName + "HighScore " + playerScore);
PlayerPrefs.SetString("OldHighScore", playerScore);
}
}
});
}
So going to change this and see if that solves the issue.
W
Will Brett
said
over 7 years ago
That was the issue. I was setting the wrong PlayerPrefs on login so it thought the score was a new highscore so it would post it to the server but the server would realise it wasn't a new score and discard it.
Will Brett
So I have noticed a bug(Probably with my code not gamesparks) where you can post score to server perfectly first time after creating account however if you then sign into that account again or another previously created account the score doesnt post which I don't understand as its the same function for posting code for a new player as previously created players and non of my debug stuff is showing any errors.
Pretty certain its working in test harness. Just posted 3 scores and all could be found in the leaderboards. I think I may have found the culprit in my unity code. Im using the same function for when I login as the one I use to check if player high score.
So going to change this and see if that solves the issue.
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstWill Brett
Think the issue is in this script as the create profile and login scripts are identical:
Irakli Geleishvili
I had error looking something similar. The scores weren't recorded after first try. Than I spotted that the scores lower than previous were recorded. The reason was - I had selected MINIMUM. In my case correct value was MAXIMUM.
Irakli Geleishvili
Sorry, I should make it more clear:
You can switch to MAXIUM from Events screen > Edit Event > Attributes > Default Calc
Will Brett
thanks but mine is def set to maximum and its works when you first create an account but then logging back in or logging into another previously made account doesnt post a score
Customer Support
Hi Will,
Have you tested this in the Test Harness ? It's always good practice to test everything there first, this way you'll know everything is working properly and if you get an error in Unity, it's probably something in your code. Are you getting any errors in the Unity console ? If you could post up a screenshot of your leaderboard configuration and any events connected to it we should be able to get it sorted for you
Thanks,
Liam
Will Brett
Pretty certain its working in test harness. Just posted 3 scores and all could be found in the leaderboards. I think I may have found the culprit in my unity code. Im using the same function for when I login as the one I use to check if player high score.
So going to change this and see if that solves the issue.
Will Brett
That was the issue. I was setting the wrong PlayerPrefs on login so it thought the score was a new highscore so it would post it to the server but the server would realise it wasn't a new score and discard it.
-
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