How do I call an Auto Load Variable in C#!!

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

So I set my player script to a global script and I’m trying reference “currentDir” on the player so I can set the direction for the projectiles to shoot. Except I don’t know how to call it. Everything I try doesn’t work but I feel like i’m really close.

The projectle (PIZZA BOX) is in another scene btw) I’ve also shortened down my code to just the necessities for THE PROBLEM OF CALLING ANOTHER VARIABLE FROM ANOTHER NODE IN ANOTHER SCENE

– Player Script –
using Godot;
using System;

public class Player : KinematicBody2D
{
PackedScene pizzaBoxScene;

public int currentDir = 1;
float speed = 65;


public override void _Ready()
{
	pizzaBoxScene = GD.Load<PackedScene>("res://scenes/PizzaBox.tscn");	
}	

public override void _Process(float delta)
{

	float totalAmount = speed * delta;



	// MOVEMENT CONTROLS

	bool moveUp = Input.IsKeyPressed((int)KeyList.W) ? true : false;
	bool moveDown = Input.IsKeyPressed((int)KeyList.S) ? true : false;
	bool moveLeft = Input.IsKeyPressed((int)KeyList.A) ? true : false; 
	bool moveRight = Input.IsKeyPressed((int)KeyList.D) ? true : false;

	int up = 0;
	int down = 1;
	int left = 2;
	int right = 3;


	Vector2 move = new Vector2(0,0);


	// Move Up
	if (moveUp == true)
	{
		move.y = -1;
		((AnimationPlayer)GetNode("AnimationPlayer")).Play("Walk Up");
		currentDir = up;    // DIRECTION SET BASED ON INPUT 
		
	}
	if (currentDir == 0 && moveUp == false)
		((AnimationPlayer)GetNode("AnimationPlayer")).Play("Idle Up");

}

– Projectile Script –
using Godot;
using System;

public class PizzaBox : Node2D
{
PackedScene GameScene;

public override void _Ready()
{	
	GameScene = GD.Load<PackedScene>("res://Game.tscn");	

	Player.Call("_Process", currentDir);  
            // RIGHT HERE IS WHERE I THINK I NEED TO CALL THE AUTO LOAD SCRIPT
}
public override void _Process(float delta)
{


           // Right here is just a bunch of code for it to move but its usless if I can't control the direction 
            it spawns  in
     }	

}

:bust_in_silhouette: Reply From: Zylann

About the question itself, autoload nodes are just nodes under the root of the scene tree, which are siblings of the current scene.

root
|-CurrentScene
|-Autoload1
|-Autoload2

In GDScript, Autoload1 and Autoload2 are accessible by typing their name like a global variable as syntactic sugar. But that isn’t available in other languages.

So in C#, you may access these nodes the classic way, knowing what they actually are:

var node = GetNode<TypeOfTheNode>("/root/Autoload1")