In the video, he has it expanded over multiple lines, which I removed because it gave an even wider range of error codes for each one. Even committing it to one line breaks it, even though he uses it multiple times.
Also considering it may be related to the difference in how he is loading the scene. He has his player sprite in the same scene as the map and grabbing it from there, whereas my player is in a separate scene from the Map with the script attached there, and instanced in the main scene (should I be adding the script to the instance only? Both?)
This is my setup for loading the map:
While he uses @onready var = $" ", which threw an error for me as well.
I am a bit unsure if this a user error or maybe a change in syntax as I cant find anything relative to my problem when I google it, and still struggling to understand the interactions between scenes, any help appreciated! Super new to coding and Godot.
Under the code editor window it says “Error at (27, 22): Expected end of statement…”
That means that there is an error on line 27, 22nd character. Looking there, I can see that you put a space between Vector and 2i. It should be “Vector2i” all together.
It is unbelievable that I cannot notice something like that. I dont think I even noticed it mentioned what character in the line to look at, so thanks for that tip! I am so sorry for the frivalous mistake post. Noticed my other error was a very basic syntax error. Remembering where to use things like . _ , : ; etc is always the death of me.
Don’t be so hard on yourself! It’s only obvious to me because I have been coding for a while (but I’m no expert by any means!).
Copying other people’s code is very useful but it’s important to understand what you are copying. I recommend you learn a bit about what sort of words do what sort of stuff so you know where spaces matter and all that jazz. Just like in real language, spaces delimit units of meaning so it matters where they are. If I say “alight”, it means turn the light on, but if I say “a light” I’m talking about an source of brightness. As an example, we can decompose the offending line:
var target_tile: Vector2i = Vector2i(current_tile.x + direction.x, current_tile.y + direction.y)
var is a keyword that means that you are declaring a variable. When the computer reads this, it expects it to be followed by the name of that variable, in your case: target_tile.
The second “unit” of meaning is : Vector2i which means you give the computer a hint that the variable is of type Vector2i. Type hint is the actual technical term.
The = says that you’re initialising your variable, ie: giving it a value.
Then you have Vector2i(...) which is a function. A word with parentheses is always a function (or a method but I don’t want to go too deep here). That function is a little machine that takes something and turns it into something else. This one takes 2 integer values separated by a , and returns a vector which will fit snugly into the variable of the same type that you just declared.
Those two values are called arguments: current_tile.x + direction.x and current_tile.y + direction.y.
current_tile is an object, the . says that you’re about to name a variable contained within that object, that variable is called x. The + just means what you think it means. So the two arguments to your Vector2i function are two additions of two variables.
Basically you will find it easier to speak computer if you learn the grammar (what do verbs, nouns and adjectives do) instead of just repeating sentences.
Wow, that was actually super informative, thank you so much! I am going to check out the link now, but I really appreciate you taking the time to break all that down.