I have a constructor which is taking a enumeration argument to determine the properties of the instantiated object:
public Support(playerClass playerClass)
{
if (playerClass == playerClass.Fighter)
{
name = "Soldier";
ambush = 0;
attack = 4;
copper = 0;
defend = 4;
range = 0;
food = 1;
mode = 0;
numattacks = 1;
regen = 0;
shield = 0;
swarm = 1;
train = 0;
firstStrike = false;
type = 2;
}
}
Now when I call this constructor and pass the argument I am getting an invalid argument error from VS.
case "soldier":
while (count >= 1)
{
units.Add(new Support(playerClass));
count--;
}
break;
Any ideas? From my understanding I AM passing the enumeration argument it should be expecting? Any help would be appreciated, thanks.
Edit: Also, here is the signature of the addUnit method:
public void addUnit(int amount, string type, playerClass playerClass)
Loading
VulpesPosted Apr 5, 2013, 4:06 AM
If you called it with an argument of playerClass.Fighter then it would probably work.
If I were you I'd change the name of the enum to PlayerClass (i.e. initial upper case letter) to avoid any confusion with variables or parameters which have the same name.
Steffon ScottPosted Apr 7, 2013, 1:28 PM
Steffon ScottPosted Apr 7, 2013, 1:15 PM