error CS1002:}

im making a code to have the character move but get the error CS 1002:} and when i try to run the game it says "all compiler errors have to be fixed before you you can enter play mode! " can anyone help ill put my code below:

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

public class Player : MonoBehaviour
{
Rigidbody rigidbody;
int moveDir;

void awake() {
rigidbody = getComponent();
}

void Update(){
movedire = (int)Input.GetAXisRaw(“Horizontal”)
Debug.log(moveDir);
}

void FixedUPdate() {
rigidBody.velocity = new Vector (moveDir, rigidBody.velocity.y,0);
}

}

You have loads of typos in your code.

You need to fix them otherwise your code cannot run.

“GetComponent”
“Debug.Log”

and there are more.

1 Like

arghh thanks first time doing custom code so i guess its kind of to be expected

so i think i fixed the typos but now i get error CS1513 and the same pop up about error compiling

8418906--1113672--upload_2022-9-6_12-45-5.png
Send your updated code if you want a revised version.

Your new error reflects a missing curly brace, but I had to use Google to find that since no one remembers error codes - and I predict you’re about to get a mouthful from Kurt about exactly that :wink:

I’ll save Kurt the bother. :wink:

Ignore the error code, look at the line it tells you the error is on.

Please use code-tags and not pictures of code. C# is case-sensitive, you cannot just type upper or lower case as you please. You should be able to find and fix these errors yourself because you can use the scripting reference to find how it should be typed, how it’s used etc and again, the errors themselves tell you which line.

You don’t need to tell someone the error code. The line the error is on and the description is all you need. At some point you’re going to have to learn how to fix your own typos so I would suggest best to learn now, save you pain later. :slight_smile:

4 Likes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    Rigidbody rigidBody;
    int moveDir;

    void awake (){
        rigidBody = getComponent<Rigidbody>();
    }

    void Update() {
        moveDire = (int)Input.GetAxisRaw("Horizontal");
        Debug.Log(moveDir);
    }

    void FixedUpdate() {
        rigidBody.velocity = new Vector(moveDir, rigidBody.velocity.y,0);
    }


}

That’s NEVER going to work. No tutorial ever told you to type that!

And what on earth is MoveDire? It sounds … dire.

Go back and see how it is typed, you have to type it perfectly.

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Finally, when you have errors…

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Uhm, you have seen the image that Zalosath posted where he marked all 10 issues your original code had? Some of the errors you fixed, some you solved in a different way (It doesn’t matter how you call your rigidBody variable as long as you stick to one version). However you did ignore a few of the others that has been pointed out. Specifically Awake, GetComponent and moveDir are still misspellt.

Since it often is buried in Kurts long answers: When you get an error, you get an english, human readable sentence that describes the error. You focused on just telling us error codes and ignored the actual error message. We don’t know error codes and we will not google error codes to figure out the error message that you already have. Furthermore the error message often times include more information as well which may include the name of a variable as well as the exact line where the error happens. Instead of ignoring all that information you should start using it. If you can’t figure it out yourself you can reach out for help. But if you don’t rely the information you have you just make the issue harder for everyone that tries to help.

I don’t think anyone’s pointed out that their IDE doesn’t seem to be set up properly either? (Not sure, never used Visual Studio code). I would imagine if it were, it’d be properly indicating errors.

(I think that’s why we see a lot of posts like this. If your IDE isn’t set up properly, coding is going to be nigh impossible for beginners)

3 Likes

There’s a trend to push new developers to use VS Code for everything, because it’s what the cool kids use (along side Docker/k8s, NoSQL dbs, GraphQL…). The thing is, VSCode is not an IDE at all, it’s a (fancy) code editor. But making a game (or anything complex besides front-end web) definitely needs a full blown IDE with an advanced Debugger and Code Analysis. The hype train is doing big damage to this industry…