How can I make a KinematicBody2D variable global ????

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CarlitosCUeba

I’m trying to get the position of KinematicBody2D and put it in a global variable, how do I do that?

Ps: I use C#, but even with GDscript, can you help me.

sorry for my english!!

:bust_in_silhouette: Reply From: Help me please

For this you need to create an autoload script(say PlayerVariables) and declare a variable in that (say PlayerPosition) then you can simply access and change that variable for now use this code in your player’s script.

PlayerVariables.PlayerPosition = position 

Godot Docs can be found here

:bust_in_silhouette: Reply From: Shashank1q

first create a script and write every variable that you want to make global
then go to projects->projects settings-> autoload tab
click the folder icon to browse your script
In the ‘node name’ write name by which you want to access the script (for example write “global” )
and click Add
now your script is available globally and so the variable inside it.
to access any of the variable write < node name >. < your variable name >
in our case ‘node name’ is global.

here’s a tutorial video if you want: https://youtu.be/ZgaM-42xiZg

thanks i’ll try to do this. Anything, i come back here.

CarlitosCUeba | 2021-06-04 13:53