Godot Version
4.3
Question
`im trying to set up a combat system for my platformer where the hurtbox teleports to infront of the player when he attacks and then teleports into the pits of hell when he’s not and I wanna put it into a variable but Idk how i tried this: var mouse: Vector2 = 0, 0 but it just throws an error what do I do
You write var mouse: Vector2 = Vector2(0, 0)
instead.
Or var mouse := Vector2(0, 0)
, if you like it shorter and still type-safe.
1 Like
what about this?
if is_on_right_side == true:
hurtbox := Vector2(999999, 999999)
the colon :
defines a new variable’s type, it only applies when creating a variable with var
# definition with implicit type
var hurtbox := Vector2(222,333)
# assignment, type has already been defined
hurtbox = Vector2(444,555)
1 Like
var yourvector = Vector2.ZERO
works
Yes, but then yourvector
is a Variant. I recommend strong typing as often as possible, to reduce bugs and increase performance.