Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

"Identifier Expected" Error on an enum inside a struct

Discussion in 'Scripting' started by Minespeed1009, Oct 6, 2021.

  1. Minespeed1009

    Minespeed1009

    Joined:
    Apr 16, 2019
    Posts:
    7
    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!

    Code (CSharp):
    1. [Flags]
    2. public enum WallState
    3. {
    4.     LEFT = 1,
    5.     RIGHT = 2,
    6.     UP = 4,
    7.     DOWN = 8,
    8.     VISITED = 128,
    9. }
    10.  
    11. public struct Chunk
    12. {
    13.     public WallState[,] Walls;
    14.     public Position ChunkPosition;
    15. }
    16. // ^ struct and 2d enum array
    17.  
    18. public static Chunk[,] ConvertToChunk(WallState[,] maze) {
    19.         Chunk[,] out = new Chunk[3,3]; // <<<< error line
    20.         for (int x = 0; x < 3; x ++) {
    21.             for (int y = 0; y < 3; y ++) {
    22.                 WallState[,] temp = new WallState[5,5];
    23.                 for (int xc = 0; xc < 5; xc ++) {
    24.                     for (int yc = 0; yc < 5; yc ++) {
    25.                         temp[xc,yc] = maze[x*5+xc,y*5+yc];
    26.                     }
    27.                 } // << apparently need another?
    28.                 out[x,y] = new Chunk{ Walls = temp, ChunkPosition = new Position{ X = x, Y = y } }; // need a } after out[x,y]....
    29.             }
    30.         }
    31.     }
    32. //I'm getting an error for some reason right after I declare Chunk[,]...
    33. //I'm also getting an error that I need a semicolon instead of =...
    34. //
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    out is a keyword in C#. Call your variable results or something instead.
     
  3. Minespeed1009

    Minespeed1009

    Joined:
    Apr 16, 2019
    Posts:
    7
    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...
     
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    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://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

    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://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874