Waypoint waypoint in waypoints

I have a quick question in Lesson 130 of Tower Defense. I never declared “waypoints” anywhere, so I have an error. I rewatched 130 and 129 and couldn’t find it. Where does it go?

Hi Jim,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

If so, please share your code here, so we can help you.


See also:

I just need to know where “waypointS” is. I never created that variable

Ben implemented the variable in lecture “The Dictionary Data Structure” (currently #130). Please rewatch the lecture. Alternatively, you could compare your code to the the lecture code changes via the link in the Resources of that lecture.

I found the error and fixed it but it still didn’t work, so I copied the lecture code and pasted it and it fixed the error. Now in lesson 131, I have another problem:

The associated script (“Pathfinder” in World) can not be loaded. Please fix any compile errors and assign a valid script

Pathfinder compiles without errors Here it is.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pathfinder : MonoBehaviour
{

    Dictionary<Vector2Int, Waypoint> grid = new Dictionary<Vector2Int, Waypoint>();

    // Use this for initialization
    void Start()
    {
        LoadBlocks();
    }

    private void LoadBlocks()
    {
        var waypoints = FindObjectsOfType<Waypoint>();
        foreach (Waypoint waypoint in waypoints)
        {
            var gridPos = waypoint.GetGridPos();
            if (grid.ContainsKey(gridPos))
            {
                Debug.LogWarning("Skipping overlapping block " + waypoint);
            }
            else
            {
                grid.Add(gridPos, waypoint);
                waypoint.SetTopColor(Color.black);
            }
        }
        print("Loaded " + grid.Count + " blocks");
    }
}

I 'm starting to wonder if I should just give up.

And I’m happy to be able to answer your implied question with a simple “no”. :wink:

Please double click on the error message. A compiler error usually indicates some typo, a misplaced curly bracket or a missing semicolon. I skimmed your code but I wasn’t able to detect a mistake.

Make sure you saved your script properly.

If you cannot spot an issue, please let me know if the error message says more, and if MonoBehaviour has got the same colour as Pathfinder.

I made a txt document copy of PathFinder, deleted it in Unity and recreated it with the same name and it works now.

Fantastic. I knew you would be able to make this work. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.