Argument value and general variable value

Godot Version

` 4.3

Question

so this is a variable of gdscript 2.0
godot 4.3

var laser_direction = Vector2(1, 0)

so what we actually are doing is we are assigning Vector2 value in laser_direction keyword right ?

and this is function whare we are assined “direction” argument into laser_direction variable
(duble quotes not meant to we this is string just pointing it)

func direction_setup(direction):
laser_direction = direction

so if we done that as we know that the function argument correct me if im wrong (it’s call argument or property) function direction_setup argument don’t have any value for now even i didnt declared type of it so why we are assined it to laser_direction and make laser_direction value 0 or null

these are the last we are trying to getting result for using direction value thay dosent have any value in my opinion I know its dumb to say that. but this is what im thinking i know guys you gonna say havent you read the documentation believe me read its not only that i read gdquest grrosery index to https://school.gdquest.com/glossary

but some of line in editor make me confuse when im doing some follow along practice.

code lines by devdrache youtube how to build gun with bullets.

if direction.x > 0:
	scale.x = 1
	rotation_degrees = 0
elif direction.x < 0:
	scale.x = -1
	rotation_degrees = 0
elif direction.y > 0:
	scale.y = 1
	rotation_degrees = -90
elif direction.y < 0:
	scale.y = -1
	rotation_degrees = 90

I dont quite understand what the problem is. Can you formulate a concrete question that we can answer?

1 Like

So what are you confused about?

laser_direction = Vector2(17.3, 23.2)

can be accessed with

laser_direction.x = 17.3
laser_direction.y = 23.2
# Vector2(x, y)

This code should probably test x and y seperately:

if direction.x > 0:
	scale.x = 1
	rotation_degrees = 0
elif direction.x < 0:
	scale.x = -1
	rotation_degrees = 0

if direction.y > 0:
	scale.y = 1
	rotation_degrees = -90
elif direction.y < 0:
	scale.y = -1
	rotation_degrees = 90

Which bit is confusing you?

1 Like