• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Android Problem with Google play leaderboard, need help

NetZvezda

Member
Hey, so here is the situation. I have this code that basically logs the user in if its not already logged in and then posts the score. I have this code running on a timer. Problem is, when it logs in, it seems to skip the achievement_post_score bit. It works fine if the user is already logged in. Same thing with the button to show the leaderboard, if the user is not logged in, it logs in but won't show the board. It does show the board on second iteration.
here is the code for posting

if(achievement_available()){
if(!achievement_login_status()) achievement_login();
achievement_post_score(myid,global.playerscore);
}

any help would be appreciated.

One solution to this would be to log the user in whenever the game starts, but that seems to be intrusive so I was wondering if there were some other ways of doing it.
 

Appsurd

Member
achievement_login works asynchronously, and is therefore not finished yet when you call achievement_post_score. You could put achievement_post_score in a timer or so to test if that works for you.
 
Couldn't you check if (ds_map_exists(async_load, "name")) behind a repeating timer to see if the load has been completed (or whatever key value pair is initialised once achievement_login has done it's work) and only repeat the timer if it doesn't exist? Not sure if checking for async_load will throw an error if it doesn't exist when you do that check.
 

FrostyCat

Redemption Seeker
The Manual has an example. It clearly tells you that the piece checking async_load (or any other code that runs immediately after the login completes) must be in the Async - Social event. Asynchronous calls always start in one place and end in a separate asynchronous event, NEVER put both parts in the same piece of code.
 

NetZvezda

Member
@FrostyCat I saw the manual but I am afraid its not very clear to me. How would you change that code to post score if the user logs in? As I mentioned in my op, the easier way to implement the leaderboard is to log-in to google services before the game starts, but that seems too intrusive and I want to avoid doing that. I suppose a more logical way would be to have a log-in icon in the menu and based on whether its activated or not, have the app log the user in if its enabled and disable leaderboard altogether if its disabled.

edit: Well, I got it to work, here is my code:
var ident = ds_map_find_value(async_load,"id");
if ident==achievement_our_info
{
if global.asyncType==1
{
achievement_show_leaderboards()
}
else
{
achievement_post_score(leaderboardID,global.playerscore)
}
}
 
Last edited:
Top