0 votes

Guys, I don't know why but for the "remote" and "local" tabs aren't showing up at all. I have an auto load script set up on Node2D, but I can't get anything to work while trying to reference a global variable.

public class GameManager : Node2D // [ Global Variable ]
public int currentDir = 1;


public class Player : KinematicBody2D // [ Player Node ]
var gameManager = GetNode("/root/GameManager");
gameManager.currentDir = 1;


There's more code for the player but it's not relevant
I also get this error message for trying to use the global variable -

Invalid token '=' in class, record, struct, or interface member declaration

game error

Godot version 3.4.2
in Engine by (14 points)

1 Answer

0 votes

If you just need a script to store variables in (integers, strings, booleans) and nothing Godot related, then a static class with static properties is what you need.

using System;

namespace MyFunnyGodotGame
    public static class GameManager
        public static int CurrentDir { get; set; } = 1;

You can now just access that property from everywhere like that:

GameManager.CurrentDir = 2; 
by (1,071 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.