Godot Version
4.5
Question
Im using signals to send the player position into a global script but now its not letting me access that number from other scenes, I need to turn it into a number(not a position) for other scenes how do i do that
4.5
Im using signals to send the player position into a global script but now its not letting me access that number from other scenes, I need to turn it into a number(not a position) for other scenes how do i do that
Hi,
A vector is essentially two numbers, so, you could either change your signal to have two arguments (two numbers), or change the number argument to be of Vector2 type.
I’m not sure I understood the problem fully, so my answer may be a bit off. Could you share a bit of code if that doesn’t help?
You don’t need to do this via a signal if it is a global script. Lets say your global script is game_data and you have named it GameData. Then in your player script, when your position changes you can just update it directly.
Global file (in this example GameData or game_data.gd)
var current_player_position: Vector2 = Vector2.ZERO
# Just gave it a default value of Vector2(0, 0)
Then in your player script, when position changes you update it directly.
GameData.current_player_position = global_position
Then wherever you need it, you can just read it in another script:
var player_position: Vector2 = GameData.current_player_position
No signals needed.