Search Unity

Unity : Array list bug

Discussion in 'Scripting' started by OrdinaryDev83, Oct 28, 2014.

  1. OrdinaryDev83

    OrdinaryDev83

    Joined:
    May 8, 2014
    Posts:
    23
    I'm creating an "RPG" project and i created this script but it doesn't work i got this error:
    ArgumentOutOfRangeException: index is less than 0 or more than or equals to the list count.

    The script:
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. function Start () {
    4.     var Tom : Personnage = new Personnage();
    5. }
    6. class Character
    7. {  
    8.     var ID : Array = new Array("Human","20","false");
    9.     function Start (){
    10.         if(ID[2] == "false"){
    11.             ID.Push("welcome.");
    12.         }else{
    13.             ID.Push("you're not allowed to enter HERE GET OUT!!!");
    14.         }
    15.     }
    16.     function Character (){
    17.        Debug.Log("You are an " + ID[0] + " you have " + ID[1] + " of health " + ID[3]);
    18.     }
    19. }
    20.  
    HELP!:(

     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    In this case you shouldn't use any kind of array at all; your ID should be a class, not an array (where you'd have an enum with the race types, an int for the health, and a boolean).

    --Eric
     
  4. OrdinaryDev83

    OrdinaryDev83

    Joined:
    May 8, 2014
    Posts:
    23
    Thank you i'll optimise my script! :cool: