Search Unity

cs1002 ; expected

Discussion in 'Scripting' started by PUGZ_THE_CODER, Jul 25, 2021.

  1. PUGZ_THE_CODER

    PUGZ_THE_CODER

    Joined:
    Jul 12, 2021
    Posts:
    4
    i'm having trouble with my code early on and I need some help. the error is Assets\scripts\player.cs(25,13): error CS1002: ; expected. thanks in advance!

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

    public class player : MonoBehaviour
    {
    private bool Jump;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    if(input.getkeydown(KeyCode.Space))
    {
    Jump = true;
    }
    }

    void FixedUpdate()
    {
    Jump
    {
    GetComponent<Rigidbody>.AddForce(vector3.up*5);
    Jump = false;
    }
    }
    }
     
  2. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    First off, always use code tags while posting code snippets,

    The error message literally give you the answer, How to understand it.
    Assets\scripts\player.cs(25,13)
    Tells you which script, what line and what column on that line.
    It's literally says your missing a
    ;
    at the end of line 25. You just gotta read it and it'll become simple
     
    Bunny83 likes this.
  3. PUGZ_THE_CODER

    PUGZ_THE_CODER

    Joined:
    Jul 12, 2021
    Posts:
    4
    yes, I know that., but that line is checking whether or not jump is true, so it cant have a semicolon. do you see now. the errors multiply if I do that. also, what are code tags?
     
  4. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Code tags make your code readable: https://forum.unity.com/threads/using-code-tags-properly.143875/

    That line isn't checking if jump is true, It's just the word "Jump" sitting there on its own, doing nothing except causing compile errors.

    use an if statement to check if something is true or not:

    Code (CSharp):
    1. if (Jump)
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    You simply CANNOT get anywhere coding like this. There are four incorrect characters in the first line above, and four or five more wrong and missing characters (depending on how you want to count them) in the second line.

    If you are gonna try your hand at monkey-finger-banging tutorial code in, you have to keep this in mind or you are going to have a REALLY hard time:

    How to do tutorials properly:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    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 single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly. Fortunately this is the easiest part to get right. Be a robot. Don't make any mistakes. BE PERFECT IN EVERYTHING YOU DO HERE.

    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.

    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!
     
    Bunny83 likes this.
  6. PUGZ_THE_CODER

    PUGZ_THE_CODER

    Joined:
    Jul 12, 2021
    Posts:
    4
    thanks! i'll keep that in mind!
     
    Kurt-Dekker likes this.