views:

191

answers:

3

Hey, I currently am having trouble trying to get this to work. Here's a sample code of what I am trying. A lot has been taken out, but this should still contain the problem. I have an object, user, and an array, player. I am trying to make an array with the players in it, here:

function user(name, level, job, apparel)
{
 this.name = name;
 this.state = "alive";
 this.level = level;
 this.job = job;
 this.apparel = apparel;
}

player = new array();
player.push(new user("Main Player", 1, 1, "naked"));
document.write(player[0].name);

But it's not working, nothing's being echo'd. What am I doing wrong?

+4  A: 

You have a typo in your code.

Change

player = new array();

to

player = new Array();
rahul
Thanks for the answer.
Anonymous
Better still: use an array literal (faster): var player = [];
KooiInc
+1  A: 

Well, you've got an error. It's not array but Array.

nc3b
Wow, thanks, didn't know they could be so literally on that.
Anonymous
Javascript is case sensitive: http://wiki.answers.com/Q/Is_javascript_case_sensitive
nc3b
+1  A: 

I would do

player = [];

instead of

player = new array();

As a sanity check, try doing:

document.write("Name: " + player[0].name);
Jared Forsyth
player[] = new user("TehMeanie", 1, 1, "naked");Why wouldn't that work?
Anonymous
Its not like that. `player = []; player.push(new user("TehMeanie", 1, 1, "naked"));`
rahul
player[0] = new user("TehMeanie", 1, 1, "naked"); would work though
KooiInc