Highscore #s?

Hello,

Any idea on how could I add a highscore number list in the existing Highscore Wiki-example? I would like to have something like this:

  1. SomeName 1000
  2. SomeName 1000
  3. SomeName 1000
  4. SomeName 1000
  5. SomeName 1000
    and so on…

Thank you!!! :smile:

Can you explain what you want a bit more? The script as-is already shows how to store names/scores as part of a high score display, are you needing help building a display string or are you wanting to store information in a different way or ???

If you just want to tweak the string that’s returned by the display.php file so it lists each entry as you described, then something like this might work:

<?php
    // Send variables for the MySQL database class.
    $database = mysql_connect(...);
    mysql_select_db('my_database') or die('Could not select database');
 
    $query = "SELECT * FROM `scores` ORDER by `score` DESC LIMIT 5";
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 
    $num_results = mysql_num_rows($result);  
 
    for($i = 0; $i < $num_results; $i++)
    {
         $row = mysql_fetch_array($result);
         echo ($i + 1) . ". " . $row['name'] . " " . $row['score'] . "\n";
    }
?>

Note the changes to the last line of the for loop, the one that uses echo(). It’s just a simple tweak to how the string is built before returning it to your content.

Excelent! Thank you Higgy, thats exactly what I wanted.

Now… just one more thing… I get the scores and names of people sticked together… how can I format the GUI so that the scores appear aligned to the right and names aligned to the left? This is a thing inside Unity I guess…

Excelent! Thank you Higgy, thats exactly what I wanted.

Now… just one more thing… I get the scores and names of people sticked together… how can I format the GUI so that the scores appear aligned to the right and names aligned to the left? This is a thing inside Unity I guess…

Hello!

YET another question concerning Highscores (didn’t want to open another post just for this…)

When the player finishes the game (or dies) he is redirected to a scene with a GUI field to type in his name, with a submit button. I don’t know why but after hitting “Submit”, the score list remains “Loading Scores…” and never shows the actual list. Is there a particular reason why this happens?

Thank you

This is how the highscores are looking right now. I need those numbers to appear aligned to the right side… heeeeelp please! :sweat_smile:

78909--3035--$highscores_101.jpg

GUILayout is the best answer. There are at least a couple of different ways, depending on what you’re doing exactly. Specifically, Begin/EndArea() or Begin/EndHorizontal() and Vertical():

import UnityEngine.GUILayout;
var myStyle : GUIStyle;
var numberOfEntries = 20;

function Start () {
	myStyle.fixedHeight = 15;
	myStyle.normal.textColor = Color.white;
}

function OnGUI () {
	BeginHorizontal();
	
		BeginVertical(Width(110));
			for (i = 1; i <= numberOfEntries; i++) {
				Label(i + ". Name" + i, myStyle);
			}
		EndVertical();
		
		BeginVertical(Width(110));
			for (i = numberOfEntries; i >= 1; i--) {
				Label( (i*500).ToString(), myStyle);
			}
		EndVertical();
		
	EndHorizontal();
}

Or:

import UnityEngine.GUILayout;
var myStyle : GUIStyle;
var numberOfEntries = 20;
var column1 : Rect;
var column2 : Rect;

function Start () {
	myStyle.fixedHeight = 15;
	myStyle.normal.textColor = Color.white;
	column1 = column2 = Rect(0, 0, 100, numberOfEntries*myStyle.fixedHeight);
	column2.x += 110;
}

function OnGUI () {
	BeginArea(column1);
		for (i = 1; i <= numberOfEntries; i++) {
			Label(i + ". Name" + i, myStyle);
		}
	EndArea();
	
	BeginArea(column2);
		for (i = numberOfEntries; i >= 1; i--) {
			Label( (i*500).ToString(), myStyle);
		}
	EndArea();
}

–Eric

Patience my friend, patience. :slight_smile:

As an alternative to Eric’s suggestion you can use GUI instead of GUILayout and then break each name/score into two labels, one that is left aligned (ranking + player name) and one that is right aligned (score). You’ll need to use a GUIStyle to control left/right alignment of course. That way between Eric’s suggestion and mine you can choose between GUI and GUILayout depending on what you’re already using.

While I won’t move this conversation anywhere I can say that IMO it’s bad form to bury your GUI questions in this thread. Instead you would likely have been better off starting a new thread in the UnityGUI area as that’s now what we’re talking about. The whole point of having subject-specific areas is for folks to use them (and proper thread labels based on the actual content) so you stand a better chance of getting timely help and others who may have the same questions will more easily find, and hopefully benefit from your thread.

I’ll get off my soapbox now. :slight_smile:

That’s a black box to us, what code have you used on your “Submit” button? We have no clue how you’ve code this up so we can’t comment on how/why it might be behaving in one way or another. Please start a new thread on this topic in the UnityGUI area and let’s discuss it there. When doing so please post some sample code and if necessary, refer to this thread in your new post.

Eric5h5, thanks for the code, we will check this immediately!

HiggyB… :sweat_smile: sorry to be posting in the wrong places…our humble apologies! :roll: I’ll post this in the Unity GUI area right away!