Identifier "global" not declared in the current scope

Godot Version

4.2 1


Hello, I'm very new at programing and I'm making a simple RPG game following a few tutorials. I currently have some problems with the code because I'm trying to call a script that I called "global" to another script and it just keeps telling me that "global" isn't declared in the current scope and I don't know what to do because in the tutorial this problem doesn't happen, can someone please help me?

Here’s the code I used (the script that I’m trying to call is named “”):

extends Node2D

func _ready():
pass # Replace with function body.

func _process(delta):

func _on_bar_transition_point_body_entered(body):
if body.has_method (“LeazarSprings”):
global.transition_scene = true

func _on_bar_transition_point_body_exited(body):
if body.has_method (“LeazarSprings”):
global.transition_scene = false

func change_scene():
if global.transition_scene == true:
if global.current_scene == “Mundo 1”:

And here’s the global script:

extends Node

var current_scene = “Mundo 1” #Mundo 1 bar
var transition_scene = false

var player_exit_bar_posx = 0
var player_exit_bar_posy = 0
var player_start_posx = 0
var player_start_posy = 0

func finish_changescenes():
if transition_scene == true:
transition_scene = false
if current_scene == “Mundo 1”:
current_scene = “bar”
current_scene = “Mundo 1”

if you want global to be accessable from anywhere in the project then you have to add it as an autoload: project → project settings → autoload tab


Thank you for your response. I did add it as an autoload in the beggining and I tried to re-do it because it wasn’t working. I still don’t know what’s wrong.

Did you name your autoload “global”? It’s the name that you give the autoload is what you have to call in your code, not the name of the script file.

You can print you autoloads like this:

for autoload in get_tree().root.get_children():
		if autoload != get_tree().get_current_scene():

If it’s ok, yours should print something like

1 Like

Thank you so much for your help, the problem is solved. :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.