I have a new question I have imputed the script "position += velocity * delta" as mentioned on the official Godot web page.

Exact quotes below:

"position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)"

I got the error "error (33,1) Unexpected token: Identifier:position "

I am not sure what to do with this information.

Any help would be appreciated.

You guys are awesome

    The code looks fine. Your problem is probably somewhere else.

    Carmes Did you fix line 30? That one reads func _velocity(0,0), which is wrong and might be the reason for the error.

      Carmes as mentioned by @Toxe, the error is in the function definition as it is missing a ':'...

      func _velocity(0, 0): # <- ':' here to end the function declaration
          position += velocity * delta
          # the rest of the code

      Note the formatting (e.g. spaces or tabs that align your code) are also important. Always worth taking a break and double-checking the code against the docs (to fix further script errors!).

      But I think what you really want to do is as stated in the docs and remove the func _velocity(0, 0):

      Add the following to the bottom of the _process function (make sure it's not indented under the else):
      position += velocity * delta
      position.x = clamp(position.x, 0, screen_size.x)
      position.y = clamp(position.y, 0, screen_size.y)

      • Zini replied to this.

        I figured out what went wrong with a decent chunk of the coding, it was indentation problems (noob move me). I also removed func _velocity(0,0).

        Currently there is an error in the code: "position.y = clamp(position.y, 0, screeen_size.y)".

        I have changed the indentation but nothing has happened.

        The error reads "identifier "screen_size" isn't declared in the current scope"

        the previous code for screen size reads: " screen_size = get_viewport_rect().size" as requested by the document.

        I am not sure how to remedy this situation.

        Any advice would be greatly appreciated.

        Thank you.

        I think it would be best if you post the complete code and error message.

        Just figured out the issue, From this experience I learned two things.

        1) I need to tinker around with indents more

        2) I need to get better at finding typos.

        Thank you for all your aid.

        Another error has manifested in line 32 elif velocity.y != 0:

        I have tinkered with the spelling and indentation but it is not working.

        the error is as follows: Error parsing expression, misplaced elif. I copied the instructions as stated within the web page:

        https://docs.godotengine.org/en/3.5/getting_started/first_2d_game/03.coding_the_player.html

        I am still not sure what to do with this information

        my code is below, I hope this aides in answering my question.

          Carmes The if-statement syntax is:

          var n = 42
          
          if n == 42:
              print("yay!")
          elif n == 69:
              print("oh là là")
          elif n == 0:
              print("meh")
          else:
              print("whatever")

          else can only be the last clause, elif comes before it.

          https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html#if-else-elif

          I have updated the code by placing the elif above the else. (see code below). Error has not changed. (Error parsing expression, misplaced elif)

          I attempted to change elif to if to see if that would work, it did but created a series of errors undone through indents before getting another error (Error parsing expression, misplaced else). So undid that and now my code is as below. I am wondering two things:

          1. Is there anything else I can do to fix this error?
          2. Has anyone completed the tutorial and have the script in screen shot form so I may use it as reference to see where I am going wrong in following the instructions?

          Thank you for your aid in this process.

          • Toxe replied to this.

            Carmes Has anyone completed the tutorial and have the script in screen shot form so I may use it as reference to see where I am going wrong in following the instructions?

            Only for Godot 4 but I don't think that helps much.

            • Line 31 is indented one level too much. Needs to be the same level as the if and else.
            • Line 32 + 33 need to be indented one more level, like line 29.
            • Line 42 is indented too much as well.

              Yes I am and yes I am will do so again. Thank you. 🙂

              Toxe Thank you for your aid this ended that error. It however revealed another. I will tinker with that before asking for help again, however.

              I have found a yellow warning but no errors but the sprite would not appear on screen.

              All the information can be seen in the above screenshots. Any advice would be greatly appreciated.

                Carmes The editor is saying the body parameter that is passed into _on_Player_body_entered isn't used (yet). It is just a warning and can likely be ignored for now.

                A warning like this could mean the programmer has made a mistake; perhaps the intention was to use a variable and they didn't? Or maybe they thought they did but have misspelled something (for example) so should always be checked. If you want to suppress the warning, the editor indicates you can change it to _body:

                func _on_Player_body_entered(_body):
                    pass

                And the warning will disappear. But it's likely you'll use it in the tutorial so don't worry too much if you understand why the warning has appeared.

                Note: you have a pass statement here that should also likely be removed before the statements following it (emit_signal, etc). This probably won't fix the sprite issue (possibly something else, worth reviewing the manual again...) but it’s unnecessary.

                Keep going!

                I have just figured out, why I could not see the sprite, I however still cannot make the character move.

                The full script is seen below, thank you for your aid.