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 #26993703 by RaIix

Edited

At 9/2/21 12:31 AM, OviManic wrote: Does that mean any test function calls should be stored in a separate <script> below the other API codes?


I don't think "below" is going to do much, because the API is called asynchronously (you send a request, some time passes, and you get a response). This won't work (pseudocode):

var medals;
ngio.getMedals( |save to medals variable| );
medals.forEach((medal) => { |stuff| }); // getMedals() didn't get a response at this point yet


That's why Ngio uses callbacks (pass a function that will be called once the method is done). E.g.:

ngio.requestLogin(onLoggedIn, onLoginFailed, onLoginCancelled);

function onLoggedIn() { |logged in successfully| }
function onLoginFailed() { |failed to log in for some reason| }
function onLoginCancelled() { |the user refused to log in| }


Looking at your game:

iu_406884_4428769.png

my guess is that you attempt to get the list of medals too early before everything is properly initialized.


I'd take a look at the examples here, see if it helps. Generally, first and foremost you initialise ngio with your app id and encryption key, then initSession (requestLogin if needed) and then you may use it as you wish (use callbacks from onLoggedIn).

If you're working with some engine that destroys objects between scenes/levels (e.g. Unity), make sure to pass the initialized ngio object between the scenes.


At 9/2/21 12:31 AM, OviManic wrote: Does that mean any test function calls should be stored in a separate <script> below the other API codes?


I don't think "below" is going to do much, because the API is called asynchronously (you send a request, some time passes while your other code continues to execute, and you get a response later). This won't work (pseudocode):

var medals;
ngio.getMedals( |save to medals variable| );
medals.forEach((medal) => { |stuff| }); // getMedals() didn't get a response at this point yet


That's why Ngio uses callbacks (pass a function that will be called once the method is done). E.g.:

ngio.requestLogin(onLoggedIn, onLoginFailed, onLoginCancelled);

function onLoggedIn() { |logged in successfully| }
function onLoginFailed() { |failed to log in for some reason| }
function onLoginCancelled() { |the user refused to log in| }


Looking at your game:

iu_406884_4428769.png

my guess is that you attempt to get the list of medals too early before everything is properly initialized.


I'd take a look at the examples here, see if it helps. Generally, first and foremost you initialise ngio with your app id and encryption key, then initSession (requestLogin if needed) and then you may use it as you wish (use callbacks from onLoggedIn).

If you're working with some engine that destroys objects between scenes/levels (e.g. Unity), make sure to pass the initialized ngio object between the scenes.