A new expression requires () or [] after type

I’ve been working with a modified version of the KeyCombo script, and converting it to C# for my project. As with KeyCombo, it requires an array of strings to be passed, which will be compared with the input from users. However, I’m having issues with it in C#. I’m pretty sure it’s an issue with the string.

Here is the constructor for the KeyCombo class script

public KeyCombo(string[] b){
		buttons = b;
	}

here is one of the places i use the keyCombo class

KeyCombo dash = new KeyCombo(["left", "left"]);

error CS1526: A new expression requires () or [ ] after type
Internal compiler error during parsing, Run with -v for details

I’ve been getting these two errors. I’m not entirely sure what the second means. I’ve put parenthesis around the declaration, so im not sure what the issue is.

That’s not C# syntax; use {} for arrays instead of [ ].

–Eric

Hi, I have been getting the same error for this line:

FileStream fileStream = new FileStream(D:/Temp/ljk;fsd/Assets/txts/dataPoint0.txt, FileMode.Open);

Hi

Your code

KeyCombo dash = new KeyCombo(["left", "left"]);

is javascript, python, ruby, haskel’s grammer.

should be

KeyCombo dash = new KeyCombo(new string[] { "left", "left" });

Is that the actual code? Because you’re incorrectly passing the string in, which should cause a different error.

Yes, that’s the actual code, and that is the error I’ve been getting. Should the file location be set up as a string (" ")?
Besides that though, I think I have a bigger problem.

Hey I’m pretty new to this and I saw that people were getting stuck with this. I’ve tried to fix the line of code that I’ve been getting errors from but so far nothing seems to have worked, I’m using C# and this is the line that’s giving me grief:

Vector3 moveVector = new Vector3.zero;

Usually I’d be using the FPS prefab but I wanted to create my own movement script and after following an online tutorial exactly I still came across this error.

Remove the “new”.

–Eric

1 Like

Thank you :smile:

Thank you so much, how do you know this?

Because Vector3 is a struct. Similarly, you wouldn’t use “float someNumber = new 0.0f” either.

–Eric