Hi there.
At 9/14/21 04:52 PM, ZabuJard wrote:
i followed the unity pdf guide.
No – not quite. This is your code:
void Start()
{
ng_core.onReady(() =>
{
requestLogin();
ng_core.checkLogin((bool logged_in) => {
if (logged_in)
{
onLoggedIn();
}
else
{
requestLogin();
}
});
}
Also, right after that:
void Update()
{
int scoreValue = 706;
NGSubmitScore(10792, scoreValue);
}
The visual pdf guide by GeckoMLA19097 looks slightly different.
You need to understand that every time you call something with ngio, it's not instant. It takes some time, while your other code continues to execute.
That means you call requestLogin and then immediately you checkLogin but it will fail if you're not already logged in, resulting in another requestLogin call. It might have worked in Editor because you were already logged in from your previous attempts or something.
Don't attempt to post the score in Update, either. That's sending many, many calls per second until you quit the game and you should definitely avoid that.
GameObject.Find(string).GetComponent() in Update is also slow as heck by the way, but that's probably a discussion for another time.
If you want to test things quickly, add the post score function to OnClick event of a button or something, like this:
public int scoreboard_id = 10792;
public void NGSubmitScore(int score)
{
io.newgrounds.components.ScoreBoard.postScore submit_score = new io.newgrounds.components.ScoreBoard.postScore();
submit_score.id = scoreboard_id;
submit_score.value = score;
submit_score.callWith(ng_core, OnScoreSubmitted);
}
void OnScoreSubmitted(postScore post)
{
Debug.Log($"Post '{post.score.formatted_value}' score to scoreboard '{post.scoreboard.name}'.");
var txt = GameObject.Find("Textz").GetComponent<Text>();
txt.text = "submitted score";
}
I edited your code slightly, see here: NgHelper Test.zip. I didn't test it on Newgrounds, but it's essentially the same code from the pdf guide. Let me know if it helps.