K
Kokolums
I'm writing a little javascript program to help keep track voting logs
for a game of "werewolf".
I then tried to add an array to my object constructor and the code
went kablooey on me. I feel lost here.
//object constructor
function VoterRecord(name, angrymob, tally) {
this.name = name;
this.angrymob = angrymob;
this.tally = tally;
That constructor works if angrymob is just a simple variable, as shown
in the code snippet below:
i = 0;
village = new Array(50);
for (var i=0; i<49; i++)
village = new VoterRecord("","",0);
But angrymob needs to be an array filled with the names of people
voting to lynch the person. Its when I try that (as in the code
below) it goes kablooey:
village = new Array(50);
mob = new Array(20);
for (var i=0; i<49; i++)
village = new VoterRecord("",mob,0);
I really don't know the syntax here. How do you put an array in an
object? I'm lost.
for a game of "werewolf".
I then tried to add an array to my object constructor and the code
went kablooey on me. I feel lost here.
//object constructor
function VoterRecord(name, angrymob, tally) {
this.name = name;
this.angrymob = angrymob;
this.tally = tally;
That constructor works if angrymob is just a simple variable, as shown
in the code snippet below:
i = 0;
village = new Array(50);
for (var i=0; i<49; i++)
village = new VoterRecord("","",0);
But angrymob needs to be an array filled with the names of people
voting to lynch the person. Its when I try that (as in the code
below) it goes kablooey:
village = new Array(50);
mob = new Array(20);
for (var i=0; i<49; i++)
village = new VoterRecord("",mob,0);
I really don't know the syntax here. How do you put an array in an
object? I'm lost.