At 6/22/20 03:56 PM, BlueStarGeneral wrote:
void LateUpdate()
{
if(!executed && ngio_core)
{
// Do this after the core has been initialized
ngio_core.onReady(() => {
// Call the server to check login status
ngio_core.checkLogin((bool logged_in) => {
if (logged_in)
{
OnLoggedIn();
executed = true;
}
else
{
/*
* This is where you would ask them if the want to sign in.
* If they want to sign in, call requestLogin()
*/
}
});
});
}
}
I didn't try your code, but by the look of it, it'd make sense why it doesn't work if the player is logged out, or in Unity.
"ngio_core.checkLogin / bool logged_in" will be false when you open the Editor, and since the "else" branch is empty, the code does nothing.
You need to actually call the commented-out ngio_core.requestLogin function (with the callbacks if you want – e.g. set the 'executed' bool to true in the first one), which will open the browser and tell you to log in (or grant permission).
I'd take a look at the visual guide by GeckoMLA19097 if you get stuck. It's fairly detailed and shows all the code you need to set up a basic working medal / scoreboard system.
I think you don't need to deal with the login bit either, if you don't want to. It only gives logged-out players an option to sign in and makes sure you can test the medals and score directly from Unity.
If you don't need that, the rest should work for logged-in players on NG nevertheless. Assuming the ngio_core has been initialised (is "ready"), this should work fine:
public void PostScore(int score)
{
var scoreboard = new io.newgrounds.components.ScoreBoard.postScore
{
id = SCOREBOARD_ID,
value = score
};
scoreboard.callWith(NGIO_CORE, OnScorePost);
}
void OnScorePost(postScore post)
{
Debug.Log($"Post '{post.score.formatted_value}' score to scoreboard '{post.scoreboard.name}'.");
}