"Identifier Expected" Error on an enum inside a struct

I haven’t worked much with structs or enums, but after having a look at a couple of tutorials, I thought they were quite easy. I thought about setting an enum inside a struct, such as for chunk manipulation with a 2d array of an enum, but for some reason it says I need a comma in the middle of the variable I’m setting!

[Flags]
public enum WallState
{
    LEFT = 1,
    RIGHT = 2,
    UP = 4,
    DOWN = 8,
    VISITED = 128,
}

public struct Chunk
{
    public WallState[,] Walls;
    public Position ChunkPosition;
}
// ^ struct and 2d enum array

public static Chunk[,] ConvertToChunk(WallState[,] maze) {
        Chunk[,] out = new Chunk[3,3]; // <<<< error line
        for (int x = 0; x < 3; x ++) {
            for (int y = 0; y < 3; y ++) {
                WallState[,] temp = new WallState[5,5];
                for (int xc = 0; xc < 5; xc ++) {
                    for (int yc = 0; yc < 5; yc ++) {
                        temp[xc,yc] = maze[x*5+xc,y*5+yc];
                    }
                } // << apparently need another?
                out[x,y] = new Chunk{ Walls = temp, ChunkPosition = new Position{ X = x, Y = y } }; // need a } after out[x,y]....
            }
        }
    }
//I'm getting an error for some reason right after I declare Chunk[,]...
//I'm also getting an error that I need a semicolon instead of =...
//

out is a keyword in C#. Call your variable results or something instead.

Sorry, right after sending this I saw that ‘out’ was highlighted, and I completely forgot it’s technically not usable as a variable. I’ve changed the line to Chunk[,] chunkOut = new Chunk[3,3]; and it works. Funny how VSCode didn’t highlight that for me…

1 Like

It does indeed do that from time to time, plus sometimes it is ultra-laggy before it highlights / helps you.

The most common fastest fix is just the whole Assets → Open C# Project from within Unity. And if you need more, here’s my standard blurb:

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

https://discussions.unity.com/t/778503

Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button

Also, this: https://discussions.unity.com/t/805330/7