I'm trying to access the score board and keep getting errors, even though it seems to be working. This would be fine but it is making my iOS build crash.
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW+<Execute>d__6.MoveNext ()
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW+<WaitForRequest>d__3.MoveNext ()
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.game;
using com.shephertz.app42.paas.sdk.csharp.user;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SetupScreen : MonoBehaviour
{
public InputField userName;
public Text errors;
private ScoreBoardService scoreBoardService;
private void Start()
{
App42Log.SetDebug(true);
App42API.Initialize(Strings.App42.API_KEY, Strings.App42.SECRET_KEY);
scoreBoardService = App42API.BuildScoreBoardService();
}
public void SubmitUserName()
{
string name = userName.text;
if (!string.IsNullOrEmpty(name))
UserNameUniqueCheck(name);
else
errors.text = "Enter a username ya dope!";
}
private void UserNameUniqueCheck(string name)
{
scoreBoardService.GetLastScoreByUser(Strings.App42.GAME_NAME, name, new CheckForScoreCallBack(this));
}
internal void ScoreDoesntExist()
{
string name = userName.text;
int score = PlayerPrefs.GetInt(Strings.Prefs.HIGHEST_SCORE);
PlayerPrefs.SetString(Strings.Prefs.USERNAME, name);
scoreBoardService.SaveUserScore(Strings.App42.GAME_NAME, name, score, null);
scoreBoardService.GetLastScoreByUser(Strings.App42.GAME_NAME, name, new SaveScoreCallBack(this));
}
internal void ScoreExists()
{
errors.text = "Username taken ya scrub!";
}
internal void ShowSavingError()
{
errors.text = "Uh oh, why no internets?";
}
internal void ChangeScene()
{
UnityEngine.SceneManagement.SceneManager.LoadScene(Strings.Scene.TITLE);
}
private class CheckForScoreCallBack : App42CallBack
{
private SetupScreen sc;
public CheckForScoreCallBack(SetupScreen sc)
{
this.sc = sc;
}
public void OnSuccess(object response)
{
sc.ScoreExists();
}
public void OnException(Exception e)
{
sc.ScoreDoesntExist();
}
}
private class SaveScoreCallBack : App42CallBack
{
private SetupScreen sc;
public SaveScoreCallBack(SetupScreen sc)
{
this.sc = sc;
}
public void OnSuccess(object response)
{
Game game = (Game)response;
string userName = PlayerPrefs.GetString(Strings.Prefs.USERNAME);
for (int i = 0; i < game.GetScoreList().Count; i++)
{
string un = game.GetScoreList()[i].GetUserName();
if (un.Equals(userName))
{
string scoreId = game.GetScoreList()[i].GetScoreId();
PlayerPrefs.SetString(Strings.App42.SCORE_ID, scoreId);
break;
}
}
sc.ChangeScene();
}
public void OnException(Exception e)
{
Debug.Log(e.Message);
sc.ChangeScene();
}
}
}