-
[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.
-
Designer, Programmer, Musician
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
-
Client Software Programmer
my dawgie angelhdz stays helping ^ you the man
-
.
Hi, this can help you with sorting the scores at least,
PHP Code:
scoreArray = [20, 30, 10, 40, 60, 50, 90, 70, 80, 100];
function highNumbers(a, b)
{
return ((a < b) - (a > b));
}
function lowNumbers(a, b)
{
return ((a > b) - (a < b));
}
for (i = 0; i < scoreArray.length; i++)
{
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 = [20, 30, 10, 40, 60, 50, 90, 70, 80, 100];
trace("Original: " + scoreArray);
scoreArray.sort(Array.NUMERIC);
trace("low to high: " + scoreArray);
scoreArray.reverse();
trace("High to low: " + scoreArray);
-
.
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 = [20, 30, 50, 60, 40, 90, 70, 80];
var Placing:Array = Scores.sort(Array.RETURNINDEXEDARRAY | Array.DESCENDING);
Scores.sort(Array.DESCENDING);
for (var j = 0; j < Placing.length; j++) { GetPlayer = Placing[j] + 1; trace("Position: " + (j + 1) + " -> player: " + GetPlayer + " - scored " + Scores[j]); }
Last edited by fruitbeard; 08-29-2013 at 10:22 AM.
-
sorry for the late response, going to see if i understand/can easely use your codes
thx!
-
@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.
-
new question 3: where do i even put the code to start with, all of it on frame 1?
thx in advance!
-
.
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:
-
.
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:
-
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 !!!
-
.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|