I have found nothing to answer this question, and I think it is different for my code. Probably because I am adding a custom object to an array, but I still don't know what is causing this. The error is on line 35. Code attached below.
using System;
class Player {
public string abilitySet;
public string name;
public void useAbility() {
if (abilitySet == "fire") {
Console.WriteLine(name + " used fireball which did 40 damage!");
}
}
}
class Match {
public int PlayerCount;
public Player[] players;
public void Start() {
Console.WriteLine("Game started! There are " + PlayerCount + " players!");
}
}
class Program {
public static void Main(string[] args) {
Match match = new Match();
Console.WriteLine("How many players are there?");
string playerCount = Console.ReadLine();
if (Int32.TryParse(playerCount, out int j)) {
Console.WriteLine("You have selected " + playerCount + " players!");
match.PlayerCount = j;
for (int i = 0; i < j; i++) {
Player plr = new Player();
match.players[i] = plr;
plr.name = "Player " + i;
Console.WriteLine("What do you want " + plr.name + "'s ability set to be?");
string ability = Console.ReadLine();
if (ability.ToLower() == "fire") {
Console.WriteLine(plr.name + " has " + ability + "!");
} else {
Console.WriteLine("That is not a ability!");
}
}
} else {
Console.WriteLine("Please enter a number of players not text!");
}
}
}