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 Encapsulation and Arrays Ternary If

I don't know what's wrong

I compiled my code and got this in the console: Game.cs(13,31) : warning CS0219: The variable 'path' is assigned but its value is never used

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Can you post us a snapshot of your workspace? It's the easiest way to help you troubleshoot your problem. :smiley:

4 Answers

Julian Lang
Julian Lang
8,428 Points

It is exactly what the message says: in one line you create a variable with the name "path" of type MapLocation array. But after creating it you never did anything with it. E.g. You could invoke a method or do whatever you have in mind to do like:

Path[0].doSomething();

In that code snippet you would grab the first item at index 0 and invoke a method named "doSomething" (which probably do not exist - it just for example purposes). Actually the answee to your problem is a conter question: What do you want the code to do? Because currently the code actually doesn't do anything..

PS: I didn't watch the lessons but I have knowledge of C#. Unfortunately it's hard for me to predict what you want to do with your path. Since its a game the path seems to Contain way points for a bot or so. I only can guess, but you might want to give those waypoints to a player figure in your game, like:

// this is just pseudo code since I don't know exactly if a class player is existing

MapLocation[] path = ... ; Player bot = new Player(); // now USE the path variable bot.Waypoints = path;

Hope that helps.

using System;

namespace TreehouseDefense
{
    class Game
    {
        public static void Main()
        {
            Map map = new Map(8, 5);

            try
            {
                MapLocation[] path = {
                    new MapLocation(0, 2, map),
                    new MapLocation(1, 2, map),
                    new MapLocation(2, 2, map),
                    new MapLocation(3, 2, map),
                    new MapLocation(4, 2, map),
                    new MapLocation(5, 2, map),
                    new MapLocation(6, 2, map),
                    new MapLocation(7, 2, map)
                };
            }
            catch(OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch(TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch(Exception)
            {
                Console.WriteLine("Unhandled Exception");
            }
        }
    }
}

I had the same compiler issue occur. I downloaded the files, and double checked against my code. Everything looked the same so I pasted the code in the dl over my own, and the same warning was returned.

Not sure why the warning wasn't returned when he compiled on the vid - magic I guess!

I'm moving on bc I don't want to spend anymore time on this, BUT I wanted to let you know I couldn't figure it out either.. :) you are not alone.

I am having the same issues as well. I decided to move on an attempt to figure it out at a later time