Error Global not declared in the current scope how to fix?

Hi i have this error if anyone can help i will be thankful i just want to understand why it happens?
this is my script
extends CharacterBody2D

var PlayerBody: CharacterBody2D
var input
@export var speed = 100.0
@export var gravity = 7

#variable for jump
var jump_count = 0
@export var jump_force = 250
@export var max_jump = 2

#State machining
var current_state = player_states.MOVE
enum player_states {MOVE, SWORD, DEAD}

Called when the node enters the scene tree for the first time.

func _ready():
$Sword/Sword_colider.disabled = true
Global.PlayerBody = self

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _physics_process(delta):
match current_state:
player_states.MOVE:
movement(delta)
player_states.SWORD:
Sword(delta)

func movement(delta):
input = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)

if input !=0: 
	if input > 0:
		velocity.x += speed * delta
		velocity.x = clamp(speed, 100.0, speed)
		$Sprite2D.scale.x = 1
		$Sword.position.x = 19
		$AnimationPlayer.play("Walk")
	
	if input < 0:
		velocity.x -= speed * delta
		velocity.x = clamp(-speed, 100.0, -speed)
		$Sprite2D.scale.x = -1
		$Sword.position.x =  -19
		$AnimationPlayer.play("Walk")
		

if input == 0:
	velocity.x = 0
	$AnimationPlayer.play("Idle")

#code for jumping
if is_on_floor():
jump_count = 0

if !is_on_floor():
	if velocity.y < 0:
		$AnimationPlayer.play("Jump")
if velocity.y > 0:
		$AnimationPlayer.play("Fall")
	
		
	

if Input.is_action_pressed("ui_accept") && is_on_floor() && jump_count < max_jump:
	jump_count += 1
	velocity.y -= jump_force
	velocity.x = input
if !is_on_floor() && Input.is_action_just_pressed("ui_accept") && jump_count < max_jump: 
	jump_count += 1
	velocity.y -= jump_force
	velocity.x = input
if !is_on_floor() && Input.is_action_just_released("ui_accept") && jump_count < max_jump:
	velocity.y = gravity
	velocity.x = input

if Input.is_action_just_pressed("ui_Sword"):
	current_state = player_states.SWORD

	
gravity_force()
move_and_slide()

func gravity_force():
velocity.y += gravity

func Sword(delta):
$AnimationPlayer.play(“Sword”)
input_movement(delta)

func input_movement(delta):
input = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
if input !=0:
if input > 0:
velocity.x += speed * delta
velocity.x = clamp(speed, 100.0, speed)

	if input < 0:
		velocity.x -= speed * delta
		velocity.x = clamp(-speed, 100.0, -speed)
		
	if input == 0:
		velocity.x = 0
move_and_slide()

func reset_states():
current_state = player_states.MOVE

Question

Did you added Global in autoloads?

2 Likes

Ok now i have an error that the script i put for the globale doesn’t work :slight_smile:

What is the error?

I’ve had errors before due to Godot being case sensitive.

Show me a screenshot in autoloads tab and tell me the error


I think i will start from scratch thanks for the help anyway T.T

It showing your script has an error, that wrong node path

yeah i just started from scratch and it stopped the error thanks anyways

1 Like

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