The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 3 of 3

Thread: [AS 2.0] High Score's with a twist

  1. #1

    [AS 2.0] High Score's with a twist

    Hello all,

    Okay so I'm making a high score table for a game me and a friend have been developing it only needs to contain a three letter name and a score.

    So far I have whipped up some test action script which looks like this:

    Code:
    var scoreEntry        :Array = [{playerName:"Adam",score:1254},{playerName:"Ben",score:4352},{playerName:"Chris",score:7896},{playerName:"Dan",score:100000},{playerName:"Ed",score:8900}];
    
    function onEnterFrame(){
        scoreEntry.sortOn("score", Array.NUMERIC | Array.DESCENDING);
        highScore.highScoreOne = scoreEntry[0].playerName+" "+scoreEntry[0].score;
        highScore.highScoreTwo = scoreEntry[1].playerName+" "+scoreEntry[1].score;
        highScore.highScoreThree = scoreEntry[2].playerName+" "+scoreEntry[2].score;
        highScore.highScoreFour = scoreEntry[3].playerName+" "+scoreEntry[3].score;
        highScore.highScoreFive = scoreEntry[4].playerName+" "+scoreEntry[4].score;
    }
    Now this works fine for some test code. (Gotta love the sortOn function!)

    Here comes the twist, when the player comes to enter their name if they make it to the end of the game the only keys I have avaliable to them to enter their name is a,b,up,down,left,right.

    Whats the reason for this I here you cry...well it looks a little somthing like this:



    As I'm still learning actionscript and for some reason actually loving the challenge of learning somthing new etc what I'm really looking for is some brain storming or a nudge in a good direct rather than an actual soloution.

    At the moment I'm leaning towards using up and down to cycle through the
    ASCII key code and using the A or B button to lock the selected code and then store it into an array then moving on to another function to cycle through for the next letter and so on.

    Once it reaches the max letters (3) i use the three positions in the array [0,1,2] to store the complete name in another array. Then using that array with the score var (_global.score); to store in the final array which should look like the code above.

    All of this is an just idea and have no idea if it would work, I'm yet to test any of it.

    Was just wondering if anyone had any thoughts, ideas of their own etc. Any input would be greatly appreciated.


    Thanks in advance.

  2. #2
    Sorry for the double post but had a bit of a break through.

    Code:
    stop();
    
    var scoreEntry        :Array = [{playerName:"Adam",score:1000},{playerName:"Ben",score:2000},{playerName:"Chris",score:3000},{playerName:"Dan",score:4000},{playerName:"Ed",score:5000}];
    var letter            :Array = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
    var playerName        :Array = ["_","_","_"];
    var playerNameReset    :Array = ["_","_","_"];
    var arrayPlace        :Number = 0;
    var letterUpdater    :Number = 0;
    var nameDone        :Boolean = false;
    var scoreOne        :Number = 99999;
    var playerNameFinal :String;
    
    function onEnterFrame(){
            if(letterUpdater == 3){
                    nameDone = true;
            }else{
            if(Key.isDown(38)&&arrayPlace < 25){
                arrayPlace++
            }
            if(Key.isDown(40)){
                arrayPlace--
            }
            if(Key.isDown(65)){
                playerName.splice(letterUpdater,letterUpdater,letter[arrayPlace]);
                letterUpdater++
            }
        }
        playerNameText = playerName[0]+playerName[1]+playerName[2];
        playerNameFinal = playerNameText;
        if(nameDone == true){
        scoreEntry.push({playerName:playerNameText, score:scoreOne});
        letterUpdater = 0;
        scoreEntry.sortOn("score", Array.NUMERIC | Array.DESCENDING);
        nameDone = false;
        playerName = ["_","_","_"];
        }
        scoreMovie.highScore.highScoreOne = scoreEntry[0].playerName+" "+scoreEntry[0].score;
        scoreMovie.highScore.highScoreTwo = scoreEntry[1].playerName+" "+scoreEntry[1].score;
        scoreMovie.highScore.highScoreThree = scoreEntry[2].playerName+" "+scoreEntry[2].score;
        scoreMovie.highScore.highScoreFour = scoreEntry[3].playerName+" "+scoreEntry[3].score;
        scoreMovie.highScore.highScoreFive = scoreEntry[4].playerName+" "+scoreEntry[4].score;
    }
    This is probably the exact wrong way to go about it and really messy but it seems to work fine. The only problem i have now is when you cycle through the letter have it show in the movie clip.

  3. #3
    207
    posts
    Registered User
    I love that you're putting this in a cabinet.

    Quick aside, you should check out constants like Key.DOWN and Key.UP etc. which can make your code a little nicer than 40 and 38.

    You could have one text-field and assign it textField.text=playerName[0]+playerName[1]+playerName[2] every time you update the values. Be sure to use a monospaced font so the right-hand letters don't shift around.

    If you're really concerned about letter spacing, you could make three text-fields, and go textField0.text=playerName[0] etc..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012