Remove the () around hit. A signal isn't a function. Also, next time you get an error message, please include it in your question.
func _velocity(0.0) isn't valid GDscirpt. Not sure what that is supposed to do.
Remove the () around hit. A signal isn't a function. Also, next time you get an error message, please include it in your question.
func _velocity(0.0) isn't valid GDscirpt. Not sure what that is supposed to do.
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 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)
spaceyjase That is still not valid GDScript. 0, 0 is not a parameter list.
Zini I can't fix everything
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.
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:
Thank you for your aid in this process.
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.
if
and else
.