Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Java help: Modify reportScore to accept strings in Eclipse — Gideros Forum

Java help: Modify reportScore to accept strings in Eclipse

totebototebo Member
edited December 2015 in Plugins
Hi guys,

I need to use 32 bit integers as a score. My workaround on iOS is to send a string as a score, and if it exists convert it to a 32 bit int. This works great. I'm trying to do the same on Android, but I think my complete lack of Java skillz is letting me down.

This is the current Java code for reportScore:
    static public void reportScore(String id, long score, int immediate){
    	if(mHelper != null && mHelper.isSignedIn())
    	{
 
    		if(immediate == 1)
    		{
    			PendingResult<Leaderboards.SubmitScoreResult> result = Games.Leaderboards.submitScoreImmediate(mHelper.getApiClient(), id, score);
    			ResultCallback<Leaderboards.SubmitScoreResult> mResultCallback = new
    		            ResultCallback<Leaderboards.SubmitScoreResult>() {
    		        <a href="https://forum.gideros.rocks/profile/Override" rel="nofollow">@Override</a>
    		        public void onResult(Leaderboards.SubmitScoreResult result) {
    		        	if (sData != 0)
    		    		{
    		    			if(result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK){
    		    				GGooglePlay.onScoreSubmitted(sData);
    		    			}
    		    		}
    		        }
    		    };
    			result.setResultCallback(mResultCallback);
    		}
    		else
    		{
    			Games.Leaderboards.submitScore(mHelper.getApiClient(), id, score);
    		}
    	}
    }
In order for this to be backwards compatible and accept a string as a score I've modified it, see code below. The app freezes and crashes when submitting any score (integer or string).
   static public void reportScore(String id, long score, int immediate, String str_score){
    	if(mHelper != null && mHelper.isSignedIn())
    	{
 
    		if(str_score != null)
			{
    			score = Long.valueOf(str_score);
			}
 
    		if(immediate == 1)
    		{
    			PendingResult<Leaderboards.SubmitScoreResult> result = Games.Leaderboards.submitScoreImmediate(mHelper.getApiClient(), id, score);
    			ResultCallback<Leaderboards.SubmitScoreResult> mResultCallback = new
    		            ResultCallback<Leaderboards.SubmitScoreResult>() {
    		        <a href="https://forum.gideros.rocks/profile/Override" rel="nofollow">@Override</a>
    		        public void onResult(Leaderboards.SubmitScoreResult result) {
    		        	if (sData != 0)
    		    		{
    		    			if(result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK){
    		    				GGooglePlay.onScoreSubmitted(sData);
    		    			}
    		    		}
    		        }
    		    };
    			result.setResultCallback(mResultCallback);
    		}
    		else
    		{
    			Games.Leaderboards.submitScore(mHelper.getApiClient(), id, score);
    		}
    	}
    }
Help! :)

Niclas
My Gideros games: www.totebo.com

Comments

Sign In or Register to comment.