A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Top 5 leaderboard/score issues

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    5

    Top 5 leaderboard/score issues

    Hi all, I'm having some issues getting my top 5 score board to work.. it's done in AS3 and is saved using a shardObject - the loading/saving aspect works 100%, but the actual scores are getting confused and overwriting each other, EG if you get the top score, it replaces both the 1. and 2. place... here's my code - gameScore is working fine, I get the score from my game when it's game over, etc


    Anyone see an issue with my logic which is why it's overwriting 2 places instead of moving the data down into each place under it? I have a feeling i'm overlooking something very simple!!!

    Actionscript Code:
    function updateleaderboard():void {
        if (gamescore >= top1) {
            top5 = top4;
            top4 = top3;
            top3 = top2;
            top2 = top1
            top1 = gamescore;
           
        }
        else if (gamescore >= top2) {
            top5 = top4;
            top4 = top3;
            top3 = top2;
            top2 = gamescore;
        }
        else if (gamescore >= top3) {
            top5 = top4;
            top4 = top3;
            top3 = gamescore;
        }
        else if (gamescore >= top4) {
            top5 = top4;
            top4 = gamescore;
        }
        else if (gamescore >= top5) {
            top5 = gamescore;
        }

        scoremenu.scoretop1.text = '' + top1;
        scoremenu.scoretop2.text = '' + top2;
        scoremenu.scoretop3.text = '' + top3;
        scoremenu.scoretop4.text = '' + top4;
        scoremenu.scoretop5.text = '' + top5;
        savegame();
    }

    I want it to replace score 2 with score 1 before it replaces it with the current top score, etc to make the board seem more dynamic. (EG if you get top 1 position, all scores move down a rank)

  2. #2
    Buğra ÖZDEN
    Join Date
    Mar 2001
    Location
    Turkey
    Posts
    52
    Hi, try this code

    Code:
    var top:Array = ["1000","900","800","700","600"];
    var gamescore = 850;
    
    var runcode:Boolean;
    runcode = true;
    
    for(var i=0;i<=top.length-1;i++) {
    	if(gamescore == top[i]) {
    		trace("my: "+top[i]);
    		runcode=false;
    		break;
    		}
    	}
    
    if(runcode) {
    	top[5] = gamescore;
    	top.sort(Array.NUMERIC);
    	top.reverse();
    	trace("my: "+gamescore);
    }
    
    for(var i3=0;i3<=4;i3++) {
    	trace(top[i3]);
    }

  3. #3
    Buğra ÖZDEN
    Join Date
    Mar 2001
    Location
    Turkey
    Posts
    52
    Sorry, I could not understand your problem.

  4. #4
    Member
    Join Date
    Jul 2009
    Posts
    56
    Hmm, your code seems fine. only thing i can think of, is that gamescore was equal top1, so it looks like it duplicated. ( as you did >= )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center