Author Topic: Output Leaderboard (Player Name and Score) in UILabel.text  (Read 4955 times)

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Output Leaderboard (Player Name and Score) in UILabel.text
« on: August 07, 2012, 12:01:40 AM »
There is a JS script output of my SQL databases to GUI.Label and it works great!
But as you know, this method does not support dynamic fonts, and correspondingly different screens on the Android devices ..
I'm trying to display text in UILabel.tex from JS:
  1. public var scriptEnabled:boolean = false;  //Set to true when you want the score submitted.
  2. //public var windowRect : Rect = Rect (20, 20, 20, 20);
  3. //public var useSizeAsPadding:boolean = true;
  4. public var phpScriptFolder:String = "http://example.com/leaderboard/";
  5.  
  6. public var cellWidth:int = 100;
  7. public var sortBy:String = "var0";
  8. public var start:int = 0;
  9. public var count:int = 100;
  10. public var condition:String[]; //This is for selecting levels, usernames, etc. IE, using my default 4 variables,
  11.                                                                                 // to check for a level named demo you would type in var3 = "Demo"
  12. public var exclusionList:String[] = ["id"];
  13. public var direction:String = "DESC"; //DESC for descending ASC for ascending
  14. public var refresh:boolean = false;
  15. //public var guiID:int = 1;
  16. public var labelScore:GameObject;
  17.  
  18. private var i:int = 0;
  19.  
  20. var scores:Array = new Array("");
  21. private var gettingScores:boolean = false;
  22.  
  23. function Start()
  24. {
  25.         for(i = 0; i<= count; i++)
  26.         {
  27.                 scores.Push("");
  28.         }
  29.         i=0;
  30. }
  31.  
  32. function Update()
  33. {
  34.         if(refresh)
  35.         {
  36.                 GetScores();
  37.                 refresh = false;
  38.         }
  39. }
  40.  
  41. function GetScores()
  42. {
  43.         gettingScores = true;
  44.         var tmpExclude:String;
  45.         for(var field in exclusionList)
  46.         {
  47.                 if(field != "")
  48.                 {
  49.                         tmpExclude += field + "~";
  50.                 }
  51.         }
  52.         var conditions:String = "&conditions=";
  53.         for(i = 0; i < condition.Length; i++)
  54.         {
  55.                 conditions += condition[i].Replace("=", "----").Replace(" ", "%20") + "~"; //Replace fixes not having the extra = in a url, which breaks the url.
  56.         }
  57.         var res:WWW = new WWW(phpScriptFolder + "/getScores.php?sort=" + sortBy + "&direction="+ direction + "&start=" + start + "&limit=" + count + "&exclude=" + tmpExclude + conditions);
  58.         print(phpScriptFolder + "/getScores.php?sort=" + sortBy + "&direction="+ direction + "&start=" + start + "&limit=" + count + "&exclude=" + tmpExclude + conditions);
  59.         yield res;
  60.         print(res.text);
  61.         var resTmp = res.text;
  62.         var tmp:Array = resTmp.Split("\\"[0]);
  63.         scores = tmp;
  64.         gettingScores = false;
  65.         //NGUIScorePrint ();
  66. }
  67.  
  68. function OnGUI ()
  69. //function NGUIScorePrint ()
  70. {
  71.         if(scriptEnabled)
  72.         {
  73.                 if(scores[0] == "")
  74.                 {
  75.                        
  76.                         if(gettingScores == false)
  77.                         {
  78.                                 GetScores();
  79.                         }
  80.                        
  81.                 }
  82.                 else
  83.                 {
  84.                         Leaderboard();
  85.                 }
  86.                 if(scores[0] != "")
  87.                 {
  88.                         //Resets scores so that it looks for new information when displayed again.
  89.                         scores = new Array();
  90.                         for(i =0; i<= count; i++)
  91.                         {
  92.                                 scores.Push("");
  93.                         }
  94.                 }
  95.         }      
  96. }
  97.  
  98. function Leaderboard ()
  99. {
  100.         for(i = 0; i <= scores.Count-1; i++)
  101.         {
  102.                 var tmp:Array = scores[i].ToString().Split("\\"[0]);
  103.                 var j:int = 0;
  104.                 for(j = 0; j <= tmp.Count-1; j++)
  105.                 {
  106.                         //labelScore.GetComponent(UILabel).text = tmp[j].ToString();
  107.                         labelScore.GetComponent(UILabel).text = scores.ToString();
  108.                 }
  109.         }
  110. }

But getting the output:
hendry;87400,aLDime=);74400,taz;37900,F;37700,nat1;36400,miki ser;34400,hendry;29900,toad;29300,shaggy;21600,florent;20900,nat1;17300,msr;17000,hendry;12800,CM;10100,tttttt;9400,f2241;9100,ziol;8400,taz;7900,哦;3300,

No spaces and newline!
As I see, C# does not understand this line:
  1. var tmp:Array = scores[i].ToString().Split(";"[0]);

I know it's a matter of language JS and C #, and the answer is somewhere nearby, but I'm at an impasse and beg for help! If you can not make the "Array" from JS to C #, may be then tell how to do that would UILabel . text did sign with the appearance of a space ";" and the transfer line with ","
Excuse me, I'm newbie))
Before very grateful!!!

PhilipC

  • Guest
Re: Output Leaderboard (Player Name and Score) in UILabel.text
« Reply #1 on: August 07, 2012, 08:00:48 AM »
I think the syntax of your Split is off try something more like .Split(new Char [] {';'})

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Output Leaderboard (Player Name and Score) in UILabel.text
« Reply #2 on: December 18, 2012, 12:47:28 PM »
Rus: Пришлось вновь вернуться к этому вопросу:
En: Returned to this issue:
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System;
  4.  
  5.  
  6. public class ArrayListSort : MonoBehaviour
  7. {
  8.         public string textUnsort;
  9.         public string [] SortText;
  10.         public int i = 0;
  11.         private int numberString = 0;
  12.  
  13.         void Update ()
  14.         {
  15.                 SortText = textUnsort.Split(new Char [] {','});
  16.                 if (i >= 0)
  17.                 {
  18.                         numberString = i+1;
  19.                         GetComponent<UILabel>().text = numberString.ToString() + ".   "+ SortText[i].ToString();
  20.                         i = i -1;
  21.                 }
  22.        
  23.         }
  24. }

Получаем (we get):


1. Нужна вся таблица а не только 1ая строка
2. Вместо ";" нужны пробелы
Может мне кто нибудь помочь?
*********************************
1. Need the entire table, not just the first line
2. Instead, "" need spaces
Can somebody help me?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Output Leaderboard (Player Name and Score) in UILabel.text
« Reply #3 on: December 18, 2012, 01:15:05 PM »
This is a C# question, not an NGUI question. Look into functions that are inside the C#'s string class such as Replace.

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Output Leaderboard (Player Name and Score) in UILabel.text
« Reply #4 on: December 19, 2012, 12:36:06 AM »
Very bad .. With with Standard OnGUI no such problems!

People buy NGUI that would work easier, but in practice, the opposite is true! I regret buying a NGUI! ((

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Output Leaderboard (Player Name and Score) in UILabel.text
« Reply #5 on: December 19, 2012, 03:26:14 AM »
Well, NGUI doesn't come with a class in c#.

If your programmers can't solve a simple problem of setting up multiple lines in a label or using multiple labels, then it's a programmer problem, not a tool problem.

string.split in c#
http://msdn.microsoft.com/en-US/library/ms228388(v=vs.80).aspx
http://www.dotnetperls.com/split

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Output Leaderboard (Player Name and Score) in UILabel.text
« Reply #6 on: January 27, 2013, 08:27:52 AM »
Well, NGUI doesn't come with a class in c#.

If your programmers can't solve a simple problem of setting up multiple lines in a label or using multiple labels, then it's a programmer problem, not a tool problem.

string.split in c#
http://msdn.microsoft.com/en-US/library/ms228388(v=vs.80).aspx
http://www.dotnetperls.com/split

Thanks, it works! pity that I have not seen these examples before.. :-\