Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

If value is inside values[i] then do something

Discussion in 'Scripting' started by koodari1337, Jul 21, 2014.

  1. koodari1337

    koodari1337

    Joined:
    Jun 10, 2014
    Posts:
    4
    Hello again! I been trying to figure out how could i only show players in specific level to the scoreboard

    like
    Code (JavaScript):
    1. var TestValue = 1;
    2.  
    3. for( var i = 0; i < Players; i++ )
    4.    {
    5.       if( TestValue in Player_Level[i] )
    6.       {
    7.          //Name
    8.          GUI.Label( Rect( Screen.width/2 - 100, 230 + 20*i, 100, 30 ), "" + Player_Name[i] );
    9.    
    10.          //Score
    11.          GUI.Label( Rect( Screen.width/2 - 20, 230 + 20*i, 100, 30 ), "" + Player_Score[i] );
    12.    
    13.          //Level
    14.          GUI.Label( Rect( Screen.width/2 + 60, 230 + 20*i, 100, 30 ), "" + Player_Level[i] );
    15.       }
    16.   }
     
  2. Grim_Reaper

    Grim_Reaper

    Joined:
    Nov 5, 2013
    Posts:
    32
    Hi,
    why do you need the Testvalue?
    Try to do something like this:
    Code (CSharp):
    1. var Players[2] = new Players {"player1", "player2"};
    2.  
    3. for( var i = 0; i < Players.count; i++ )
    4. {
    5. Gui.Label( Rect( Screen.width/2 -100, 230 + 20*i, 100, 30),  Players[i]);
    6. }
    Its just an example, i did not test it.
    And i am not sure i did understand your question properly ;)
    greetings, Michael
     
  3. Grim_Reaper

    Grim_Reaper

    Joined:
    Nov 5, 2013
    Posts:
    32
    Ah ok.
    What does Player_Level return? An integer?
    If yes. Try to write your previous code and change line 5 like this.
    Code (JavaScript):
    1. if( TestValue == Player_Level[i])
     
  4. Grim_Reaper

    Grim_Reaper

    Joined:
    Nov 5, 2013
    Posts:
    32
    Could you show some more of your Script pls. Since you are using JS, i can not figure out what you expect your variables to have inside.
    I will read through it tomorrow morning. Have to get up early for work and it is 0.45 at my place hehe
    I think the problem will bei somewhere with the variable-types.
     
    koodari1337 likes this.
  5. koodari1337

    koodari1337

    Joined:
    Jun 10, 2014
    Posts:
    4
    EDIT: All works now! Thank you for help! :)
     
    Last edited: Jul 22, 2014