Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Loops and Final Touches Playing the Game

Level.cs: Invader.IsActive vs invaders.IsActive question


If I leave the code as is, 3 errors appear : The . name 'invaders' does not exist in current context. If I change the code to Invader then this error appears: An object reference is required to access non-static member TreehouseDefense.Invader.IsActive. Can you please explain why neither works and what do you recommend I do to address that.

1 Answer

Steven Parker
Steven Parker
218,692 Points

"Invader" (capital "I") is a class, not an object; but "invader" (lower case "i") has not been created yet. And "invaders" (plural) is probably just a typo.

If you look at around 3:25 in the video Putting It All Together, you'll see that some of the code added at that point is missing from your file. And it's in that missing code where "invader" gets created.