A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [RESOLVED] Determine wich variable is the highest

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    26

    resolved [RESOLVED] Determine wich variable is the highest

    Hey,

    simple question

    basicly i got 8 variables(players) with differend values(score)
    player1: score = 100
    player2: score = 90
    player3: score = 70
    player4: score = 60
    player5: score = 50
    player6: score = 40
    player7: score = 30
    player8: score = 20

    i will give players score at random
    and i want to create the most basic highscore possible for them
    how???

    i tryed to come up with simple ideas to implement it like
    if(player8) => player1234567
    player 8 = position 1
    if(player7) =>player1234568...well that doesnt work since 8 is already listed and it all gets messed up

    cant think of a simple idea to implement this,
    if there a simple code that checks what value is biggest and ranks them somehow?
    or any of you have another simple idea to make the most basic highscore?

    think of it as a simple soccer game, after a match you need to see a list with the teams ranked in the season

    thx in advance
    Last edited by Kascas; 08-27-2013 at 09:12 AM.

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Try making a function to check the score of all players and assigning the position

    PHP Code:
    function p1checkScore(){
    if (
    player1.score player2.score && player1.score player3.score && player1.score player4.score && player1.score player5.score && player1.score player5.score && player1.score player6.score && player1.score player7.score && player1.score player8.score 
    {
    player1 position1//assign here some how the first position to the player 1

    }

    }; 
    ...and so on with the other players. I haven't tested that script, so i don't know if it actually works, but I wanted to help and to think about a solution.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    my dawgie angelhdz stays helping ^ you the man

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi, this can help you with sorting the scores at least,
    PHP Code:
    scoreArray = [203010406050907080100];

    function 
    highNumbers(ab)
    {
        return ((
    b) - (b));
    }

    function 
    lowNumbers(ab)
    {
        return ((
    b) - (b));
    }

    for (
    0scoreArray.lengthi++)
    {
        
    scoreArray[i] = scoreArray[i];
    }

    trace("Original: " scoreArray);

    scoreArray.sort(lowNumbers);
    trace("low to high: " scoreArray);

    scoreArray.sort(highNumbers);
    trace("High to low: " scoreArray); 
    or
    PHP Code:
    scoreArray = [203010406050907080100];

    trace("Original: " scoreArray);

    scoreArray.sort(Array.NUMERIC);
    trace("low to high: " scoreArray);

    scoreArray.reverse();
    trace("High to low: " scoreArray); 

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    This is more like it.

    Assuming we add to the array: player 1 scored 20, player 2 scored 30, player 3 scored 50 and so on,
    PHP Code:
    var Scores:Array = [2030506040907080];

    var 
    Placing:Array = Scores.sort(Array.RETURNINDEXEDARRAY | Array.DESCENDING);

    Scores.sort(Array.DESCENDING);

    for (var 
    0Placing.lengthj++)
    {
        
    GetPlayer Placing[j] + 1;
        
    trace("Position: " + (1) + " -> player: " GetPlayer " - scored " Scores[j]);

    Last edited by fruitbeard; 08-29-2013 at 10:22 AM.

  6. #6
    Junior Member
    Join Date
    May 2010
    Posts
    26
    sorry for the late response, going to see if i understand/can easely use your codes
    thx!

  7. #7
    Junior Member
    Join Date
    May 2010
    Posts
    26
    @angelhdz thx for thinking out of the box for simple solutions, like i did
    your code is the same that i came up with, but it flaws when you start with player 2
    how am i suppose to exclude position 1, out of the > list
    if anyone knows how to, i will surely implement this long but very easy code

    @fruitbeard damn is that the closest il get to a simple highscore?
    i can barely understand what everything does, i tryed array tutorials i now got a basic understanding of how they work, but my mind is stil spinning
    i get what certain codes do, but not where to put them, how to acces them etc
    new question 1, how can i acces the scores, like score player 1 is now -10?
    new question 2, how can i put the output, in a list displayed ingame itself, just textboxes would do?



    thx in advance!
    Last edited by Kascas; 08-30-2013 at 02:39 PM.

  8. #8
    Junior Member
    Join Date
    May 2010
    Posts
    26
    new question 3: where do i even put the code to start with, all of it on frame 1?

    thx in advance!

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Did you even test the code to see what it outputted?

    Never mind that, have a look at this, it's kind of quickly put together, be sure to add your own scores in the text boxes to test it properly.

    CS5:

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Here is a reconditioned version.

    If you wanted to be able to save the scores and reload them in, then you will need to save the high scores using flash/php and save/load them in each time.


    CS5:

  11. #11
    Junior Member
    Join Date
    May 2010
    Posts
    26

    resolved

    yes! this is what i was looking for.....f9.....*dies*
    probs dont even understand 80% of the coding
    but i found how to tweak the values
    and i can most likely find out, all tweaks i need to know by myself
    so i guess my question is solved here

    thx alot!!! can finely start coding again !!!

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You might prefer this one, you need to make a text file, call it "scores.txt" and place in the same directory as the swf, with this code in it
    Code:
    &ScoreList=100,30,456,68,72,45,23,19
    it also kind of explains the code inside
    CS5:

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