00:00
00:00
Newgrounds Background Image Theme

Someone gifted MetalSlayer69 supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Edits to post #26603395 by RaIix

Edited

I tried it and ran into the same issue as you ("success" with an empty list), even though the code seemed OK to me.

I don't know if the parameters sometimes behave weirdly or if it was my fault (most likely the latter) but after a few attempts, I ended up with this parameter combination which worked with both live and a (different) preview scoreboard.


(You don't have to use the event; I just use it to feed the scores into a text field.)

public void getScores(int scoreboard_id, UnityEvent<string> onScoresGetEvent = null)
{
	// create the component
	var get_scores = new components.ScoreBoard.getScores
	{
			// set required parameters
			id = scoreboard_id,
			limit = 25,
			// user = ngio_core.current_user,
			period = "A",
			social = false,
	};

	// call the component on the server, and tell it to fire onScoreGet() when it's done.
	get_scores.callWith(ngio_core, result =>
	{
		onScoresGet(result);
		string resultString = result.scores.Cast<score>().Aggregate(string.Empty, (current, score) => current + $"{score.formatted_value}\n");
		onScoresGetEvent?.Invoke(resultString);
	});

	Debug.LogFormat("Attempting to get scoreboard '{0}' data...", scoreboard_id);
}

Handle results:

void onScoresGet(results.ScoreBoard.getScores result)
{
	if (!result.success) return; // or Debug.LogError()
	string scoresString = string.Empty;
	foreach (objects.score score in result.scores)
	{
		// this object contains all the score info, and can be cast to a proper model object.
		// var score = (io.newgrounds.objects.score) s;
		scoresString += $"<b>{score.user.name}</b>:\t\t\t\t{score.formatted_value}\n";
	}
    // Log scores or "None"
	Debug.LogFormat("<b><color=orange>Scores gathered:</color></b> {0}\n{1}", 
					result.scoreboard.name, string.IsNullOrWhiteSpace(scoresString) ? "<color=red><None></color>" : scoresString);
}


Live scoreboard test:

iu_179190_4428769.png


Preview (incremental) scoreboard test:

iu_179191_4428769.jpg


You can see the sample if you add Ngio as a package or just the code here.

iu_179192_4428769.png



At 10/10/20 09:42 PM, MayChant wrote: Hi. I'm trying to add a scoreboard to my game (in Unity3D). I created the scoreboard and made API calls to post and get scores from the same scoreboard. The post score requests always had a successful status, yet I never get any scores from the get request. I can get the scoreboard object itself but the array I get is always empty. I tried to get with period="A" and with period being left out (which defaulted to "D"), and neither way worked. I was testing it in preview mode, if that's relevant.


I tried it and ran into the same issue as you ("success" with an empty list), even though the code seemed OK to me.

I don't know if the parameters sometimes behave weirdly or if it was my fault (most likely the latter) but after a few attempts, I ended up with this parameter combination which worked with both live and a (different) preview scoreboard.


(You don't have to use the event; I just use it to feed the scores into a text field.)

public void getScores(int scoreboard_id, UnityEvent<string> onScoresGetEvent = null)
{
	// create the component
	var get_scores = new components.ScoreBoard.getScores
	{
			// set required parameters
			id = scoreboard_id,
			limit = 25,
			// user = ngio_core.current_user,
			period = "A",
			social = false,
	};

	// call the component on the server, and tell it to fire onScoreGet() when it's done.
	get_scores.callWith(ngio_core, result =>
	{
		onScoresGet(result);
		string resultString = result.scores.Cast<score>().Aggregate(string.Empty, (current, score) => current + $"{score.formatted_value}\n");
		onScoresGetEvent?.Invoke(resultString);
	});

	Debug.LogFormat("Attempting to get scoreboard '{0}' data...", scoreboard_id);
}

Handle results:

void onScoresGet(results.ScoreBoard.getScores result)
{
	if (!result.success) return; // or Debug.LogError()
	string scoresString = string.Empty;
	foreach (objects.score score in result.scores)
	{
		// this object contains all the score info, and can be cast to a proper model object.
		// var score = (io.newgrounds.objects.score) s;
		scoresString += $"<b>{score.user.name}</b>:\t\t\t\t{score.formatted_value}\n";
	}
    // Log scores or "None"
	Debug.LogFormat("<b><color=orange>Scores gathered:</color></b> {0}\n{1}", 
					result.scoreboard.name, string.IsNullOrWhiteSpace(scoresString) ? "<color=red><None></color>" : scoresString);
}


Live scoreboard test:

iu_179190_4428769.png


Preview (incremental) scoreboard test:

iu_179191_4428769.jpg


You can see the sample if you add Ngio as a package or just the code here.

iu_179192_4428769.png