0

I want to show a button in my game with the Totalnumber of increments.

theButton.setText(Integer.toString(game.appObj.firedIncrements(achString)));

Following function returns the value succesfully.

//returns -1 or the number of steps;
public int  firedIncrements(String achStringId)  {


    boolean fullLoad = false;  // set to 'true' to reload all achievements (ignoring cache)
    long waitTime = 20;    // seconds to wait for achievements to load before timing out
    // load achievements
    int steps=-1;
    PendingResult p = Games.Achievements.load( mGoogleApiClient, fullLoad );
    Achievements.LoadAchievementsResult r = (Achievements.LoadAchievementsResult)p.await( waitTime, TimeUnit.SECONDS );
    int status = r.getStatus().getStatusCode();
    if ( status != GamesStatusCodes.STATUS_OK )  {
        r.release();
        return -1;           // Error Occurred
    }

    // process the loaded achievements
    AchievementBuffer buf = r.getAchievements();
    int bufSize = buf.getCount();
    for ( int i = 0; i < bufSize; i++ )  {
        Achievement ach = buf.get( i );

        // here you now have access to the achievement's data
        if(achStringId==ach.getAchievementId())
        {
            steps = ach.getCurrentSteps();
        }
        //String id = ach.getAchievementId();  // the achievement ID string

         steps = ach.getCurrentSteps();  // current incremental steps
    }
    buf.release();
    r.release();
    return steps;
}

But it needs a wait state. Can I do this without this wait state. To be more specific, i need to access the "Achievement details" from the apiClient object directly. Is it possible for me without storing them locally in seperate data tables or preferences.?

Thanks In Advance.

VARUN ISAC
  • 443
  • 3
  • 13
  • Would it not be possible to load the data you need before creating the button? Possibly load the information during a loading screen!? – Eric Jul 14 '16 at 14:14
  • thanks..nice idea, it is possible, but i want to know how to do it momentarily from mGoogleApiClient , since i want to get the current increment state of the achievements, as the game progresses. – VARUN ISAC Jul 14 '16 at 17:43
  • I would still suggest to load the initial state during a loading screen, and then display the text you get in the button - during the game, as the state changes, show the _old_ text to the user, until the next text is returned. Maybe you could _fade_ the button out, until the text is returned by the API call? – Eric Jul 15 '16 at 11:38

0 Answers0