Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Benjamin Deollos
Benjamin Deollos
2,097 Points

Error on compiling

Hey Everyone, I keep getting this error when I am trying to compile the code for the IsActive or IsNeutralized. I have verified the syntax with what is on the video multiple times and I must be overlooking something. Here is my Code: namespace TreehouseDefense { class Invader {

  private readonly Path _path;
  private int _pathStep = 0;

  public MapLocation Location => _path.GetLocationAt(_pathStep);


  public int Health{ get; private set; } = 2;

  public bool HasScored { get {return _pathStep >= _path.Length; }}

  public bool IsNeutralized => Health <= 0;

  public bool IsActive => !(IsNeutralized || HasScored);


  public Invader(Path path)
  {
    _path = path;        
  }

  public void Move() => _pathStep += 1;  

  public void decreaseHealth(int factor)
  {
    Health -= factor;
  }

}

}

Here is the error that I am getting: treehouse:~/workspace$ mcs -out:TreehouseDefense.exe *.cs
Game.cs(25,33): error CS1729: The type TreehouseDefense.Invader' does not contain a constructor that takes0' arguments
Invader.cs(21,14): (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings

Steven Parker
Steven Parker
231,140 Points

You show the Invader module here, but the message says the error occurs in the Game module. You can share your entire workspace at once by making a snapshot of your workspace and posting the link to it here.

1 Answer

The error message states that you're probably trying to initialize an invader without passing the Path as an argument. To fix this error, you probably need to go to the Game class and add the Path as a parameter in the line where the error is located. (I'm assuming you're initializing the Invader in an array) Instead of:

...
Invader(),
...

You should have something like this:

...
Invader(Path),
...