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# C# Objects Loops and Final Touches Playing the Game

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

https://w.trhou.se/po9bmfb3gt

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
229,608 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.