Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Please tell me how to make a highscore list?

  1. #1

    Please tell me how to make a highscore list?

    Well, i need to make a highscore list, but i need to make it using textfiles! but since i am very new at programming i cant figure out how to sort the the list...i want to sort the list within flash, but how do i make it so that the names and the scores get sorted together? currently i am thinking of somehow using sortOn on the array generated using "split"....but since the information resides on a external text file, therefore this method might be very slow in practice, and especially when my target viewers are dial-up users. So what do you guys suggest?
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  2. Quote Originally Posted by bluemagica View Post
    Well, i need to make a highscore list, but i need to make it using textfiles! but since i am very new at programming i cant figure out how to sort the the list...i want to sort the list within flash, but how do i make it so that the names and the scores get sorted together? currently i am thinking of somehow using sortOn on the array generated using "split"....but since the information resides on a external text file, therefore this method might be very slow in practice, and especially when my target viewers are dial-up users. So what do you guys suggest?
    What has dial up to do with the method of sorting the array?

    What is the lay out of the textfile?

  3. #3
    You don't need to return all highscores to flash, only the amount you want to list, usually around 5 to 10, as well as the user's.

    Pass the name/score pair to your backend script, have it update the text file (if using PHP, the split, search and replace functions are similar to flash's), and return the above amount of data in a string of "name,score,name,score,name,score" etc. You can then do something like this example simulation to parse the returned data and sort it for display:
    PHP Code:
    // create some textfields 
        
    createTextField('playerText'getNextHighestDepth(), 10010010020);
        
    playerText.text 'Enter Player Name';
        
        
    createTextField('player'getNextHighestDepth(), 10014010020);
        
    player.border true;
        
    player.type 'input';
        
        
    createTextField('scoreText'getNextHighestDepth(), 10020010020);
        
    scoreText.text 'Enter Sample Score';
        
        
    createTextField('score'getNextHighestDepth(), 10024010020);
        
    score.border true;
        
    score.type 'input';
        
        
    createEmptyMovieClip('activator'getNextHighestDepth());
        
    activator._x 150activator._y 300;
        
    activator.createTextField('activatorButton'activator.getNextHighestDepth(), 0000);
        
    with(activator.activatorButton){ border trueselectable falseautoSize 'center'text 'Press to Simulate'; }
        
    createTextField('highScoreList'getNextHighestDepth(), 30050300450);
        
    with(highScoreList){ border wordWrap multiline true; }


    // this string is a simulation of the string you will be receiving after sending your name/score to the server
        
    updatedList 'Adam,'+Math.round(Math.random() * 10000)+',Barry,'+Math.round(Math.random() * 10000)+',Charles,'+Math.round(Math.random() * 10000)+',Darren,'+Math.round(Math.random() * 10000)+',Ernest,'+Math.round(Math.random() * 10000)+',Frank,'+Math.round(Math.random() * 10000)+',George,'+Math.round(Math.random() * 10000)+',Arianna,'+Math.round(Math.random() * 10000)+',Brittany,'+Math.round(Math.random() * 10000)+',Christine,'+Math.round(Math.random() * 10000)+',Dorothy,'+Math.round(Math.random() * 10000)+',Elizabeth,'+Math.round(Math.random() * 10000)+',Francine,'+Math.round(Math.random() * 10000)+',Gretchen,'+Math.round(Math.random() * 10000);

    // this would be in an onLoad or onData type of function
        
    activator.onPress = function(){
        
    // split it up at the commas
            
    splitList updatedList.split(',');
        
        
    // seed your score list with the name/score pairs as properties of an object in an array
            
    scoreList = new Array();
            for(var 
    0splitList.length+= 2){
                
    scoreList.push( { namesplitList[l], scoreNumber(splitList[1]) } );
            }

            
    // this next line is just for this simulation, it will be handled by the backend script in your app
            
    scoreList.push( { nameplayer.textscoreNumber(score.text) } );
        
            
    // sort by numeric scores in descending order
            
    scoreList.sortOn('score', Array.NUMERIC | Array.DESCENDING);
        
            
    // display the highscore list
            
    for(var 0scoreList.lengthi++){
                
    highScoreList.text += scoreList[i].name ' ' scoreList[i].score '
    '
    ;
            }
        }; 
    Last edited by Jerryscript; April 14th, 2008 at 06:04 PM.

  4. #4
    Thanks Jerryscript, this is kinda like what i did....my text file is like
    var_text=john,26 sam,24 dead,18 last,19

    I, similar to you, split the string first at " " and then at "," giving the required array, and then used same technique as yours... but the problem is, though i can get the highscore, it is showing up a bit late...i dont want that time lag.

    But anyway, i really learnt a lot from your code, thanks for the help again JerryScript.


    EDIT:: now i have a problem.

    p0.text="Game"; works
    this["p"+i].text="Game"; dosent work, anybody know why?
    Last edited by bluemagica; April 15th, 2008 at 07:03 AM.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  5. #5
    I'm not sure what the problem is with your code without seeing more of it. Maybe a scope issue since you're using "this".

    The lag issue is something you have to learn to live with, but hopefully it's not more than 150ms or so. Just toss in some sort of fancy particle effect or other animation that your highscore list emerges from, and by the time the effect is done, enough time should have elapsed for your list to be loaded, parsed, sorted, and rendered.

  6. #6
    well it is fixed now, and i have a new problem. The texts which are rendered do not have the formatting of the dynamic textbox. by formatting i mean the font and "bold"....when the text comes up it is not bold and in times new roman font....any ideas why??
    Last edited by bluemagica; April 15th, 2008 at 11:06 AM.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  7. #7
    207
    posts
    Registered User
    Did you embed the font?

  8. #8
    Nope, cause as soon as i embed the font, for some weird reason, the texts dissappear.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  9. #9
    AS2 - check the textFormat and newTextFormat

    AS3 - check the default textformat

  10. #10
    Hmm, jerryscript, does that mean i have to set the formats for all the fields in as?

    And anyway i have a BIG PROBLEM on me. I am using "split_array.sortOn('plscore', Array.DESCENDING | Array.NUMERIC)". the array was 99,88,69,7,8, and it is coming 99,8,88,7,69

    Why is this?
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  11. #11
    207
    posts
    Registered User
    It looks like it's sorting them as strings, not as numbers.

  12. #12
    I'm pretty sure the problem is that you are not seeding your plscores as numbers. They do not become numbers automatically, you have to convert them using Number() or int() or uint().

    In the code I posted above, it sorts your list of numbers fine. However, if you leave out the Number() statement when creating the array of objects, it gives the same results as you showed because the string is never converted to a number.
    PHP Code:
    // note the "score: Number(score.text)" statement
    scoreList.push( { nameplayer.textscoreNumber(score.text) } ); 

  13. #13
    actually i managed to solve it using parseInt(). but thanks for your replies...


    Anyway, this might sound a bit oftopic, but recently i saw a firefox extension, that enables to modify the outgoing flash data like score, resulting in a possible hack. For those who know about this, is there any solution against this?
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  14. #14
    Try some form of encryption and code obfuscation. Nothing is 100% safe, but that should stop most.

  15. #15
    hmm but since i dont know php well, i cant really decrypt it properly on the server side....ah well i guess i will have to learn php now.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


Page 1 of 2 12 LastLast

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