Object reference not set to an instance of an object Problem O:

Hello guys , I have a problem with this code:

var quest:quests[];

class quests
{
var questkills:int;
var questtaken:int;
var questcompleted:int;
}

function Start()
{
quest=new quests[2];
for (var i=0;i!=2;i++)
{
quests[i].questkills=0;
quests[i].questtaken=0;
quests[i].questcompleted=0;
}
}

function OnGUI()
{
		GUILayout.Label("kills:"+quest[1].questkills);
}

This is giving me the Error: “Object reference not set to an instance of an object”
Please help - Thanks Utaelilya

The error says everything.

There is no value in quest[1]

Thanks for replying
But i am making 2 new quests in start :confused:

Sorry , I am making the 0 value when the class is made*

No, you are initializing the size of the array. Not the values.

I Made new values after ive made the new arrays…

Now it still dosnt work :confused:
had this problem before (Check code at 1st post)

Edit: I get “Type ‘System.Type’ does not support slicing.” Error

Two things.

  1. You have the class and variable names mixed up (this is what is causing your error)

  2. You are still trying to assign values to the variables without creating the object

quest=new quests[2];
for (var i=0;i!=2;i++)
{
    quest[i] = new quests ();
}

Ohh Thanks ALOT , It worked!

Good thing Some are active to help on the forum =)
Thanks alot again! , This will help alot on my school project =)