Home > Software design >  How do I fix "All compiler errors have to be fixed before you can enter playmode!" error i
How do I fix "All compiler errors have to be fixed before you can enter playmode!" error i

Time:08-31

I'm a new programmer, and I've been trying to make a simple video game in unity, however I can't test my progress so far because I cannot enter the playmode in Unity... I get the message "All compiler errors have to be fixed before you can enter playmode!" and I go to check the errors, and they are the 5 following:

  • error CS1519: invalid token '{' in class, record, struct or interface member declaration

  • error CS1519: invalid token '(' in class, record, struct or interface member declaration

  • error CS8124: Tuple must contain atleast two elements.

  • error CS1519: invalid token ';' in class, record, struct or interface member declaration

  • error CS1022: Type or namespace definition, or end of file expected

And this is the code:

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

public class InputManager : MonoBehaviour
{
    private PlayerInput playerInput;
    private PlayerInput.OnFootActions onFoot;

    private PlayerMotor motor;
    // Start is called before the first frame update
    void Awake()
    {
        playerInput = new PlayerInput();
        onFoot = playerInput.OnFoot;
        motor = GetComponent<PlayerMotor>();
        onFoot.Jump.performed  = ctx => motor.Jump();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        //tell the playermotor to move using the value from our movement action.
        motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>());
    }

    private void OnEnable()
    {
        onFoot.Enable();
    }

    private void OnDisable();
    {
        onFoot.Disable();
    }

}

Could anyone tell what the mistakes mean and how I could fix them?

Thank you in advance! :)

CodePudding user response:

If you ever stumble upon error messages and don't understand their description, try to look up their codes in the internet. For example https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1519 can give you some insights about your first error. The same goes for other stuff.

Regarding error CS1519: invalid token '{' in class, record, struct or interface member declaration you can read in the documentation:

This error is generated whenever a token is encountered in a location where it does not belong. A token is a keyword; an identifier (the name of a class, struct, method, and so on); a string, character, or numeric literal value such as 108, "Hello", or 'A'; or an operator or punctuator such as == or ;.

In your case the token is ; and it doesn't belong in here: private void OnDisable();

This semicolon is the issue, as it made your method bodyless (when it should have one), as well as your method call onFoot.Disable(); is now treated as if made just inside a class, not method, which is not valid.

In general, this error usually indicate typos of all kind.

error CS1022: Type or namespace definition, or end of file expected is just a consequence of formerly mentioned semicolon, that propagates further down the file.

As for error CS8124: Tuple must contain atleast two elements. I can't see this error in the code I pasted to my project, maybe that's an error in another file you didn't paste here. But the message clearly indicates the reason: you are using a tuple, that contain less than 2 elements. Alternatively, it might be another typo, that made compiler think you are using a tuple.

CodePudding user response:

Suggestions:

(Correct me if I am wrong) you have copied the code from somewhere and trying to make it work in your game right?

So for the namespace error it might be because you haven't imported new inputSystem package from package manager in unity and as far as I understood your code other errors don't belong to this script so perhaps you have some other scripts in your project that are causing those errors when compiling...

so basically that error cannot be resolved (or in other words you can't get into play mode) unless your scripts compile correctly (without any issues/errors) so there is way with which you can check in which script is throughing that errors and on which line so you just need to go to your console of unity editor ( shortcut for windows: Ctrl Shift C ) and double click on error to see which line is causing the problem.

your errors meaning:

1st error means that you have an extra or less '{' curly bracket in your script.

2nd error means that you have an extra or less '(' parentheses (also called small bracket) in your script.

so maybe by mistake you have inserted those brackets in your code or maybe you have removed one side of the bracket in your code that also can be the reason why those errors occuring. (solution: check your scripts and put or delete brackets which are missing or if there is any extra)

3rd error means that you have a 'tuple' data type variable but it doesn't contain least number of elements in it.

so basically tuple is a data type which stores multiple type of variables in one variable (made it simple for you to understand), so as I told you before check and double click on that error and it will lead you to the line which is causing error and try to fix it then.

4rth error means (again the same like the bracket ones) that you an extra or less ';' semi colon in your script.

5th error means you are missing a reference of a namespace which in your case (if I am not wrong) is because you haven't imported the library / package of input system so...

Anyways hope you understood something new from it and I am sorry if I made it so confusing...

hope it helps... Happy coding :)

  • Related