How to make a updating player position global

Godot Version

4.4

Question

how to make func _physics_process(delta: float) -> void:var player_pos_x = $AnimatedSprite2D.get_global_position().x a global variable

Format your code using triple tick marks ```:

```
your code here
```

becomes

func _physics_process(delta:float) -> void:
    var player_pos_x = $AnimatedSprite2D.get_global_position().x

Next, specify your question better. What variable do you want to be global? player_pos_x? $AnimatedSprite2D.get_global_position().x? The way you’ve written it, you seem to want your entire physics process to be a global variable. Not to be rude, but we are not ChatGPT.

Assuming you want the player_pos_x to be global: Set up a global script (autoload) called Globals (globals.gd). Put player_pos_x there. Whenever you want to set/get this var from another script, refer to it via Globals.player_pos_x

What I ment is how would it know what animatedsprite2d is if its not in that scene since id have to make a new script to autoload idk why I put _physics_process there and I want the player_pos_x global

If it’s not in that scene, it’s presumably still somewhere in the tree. You can use an absolute path from the scene root if you need to.