## Godot Version
v 4.3
Question
This is my first time coding a project and I just learnt that global scripts were a thing, i need help because i’m not sure what’s going wrong.
I have set up a global script, the code attached to it looks like this:
extends Node
var goblin_attack = false
func test():
if goblin_attack == true:
print("global_signals works")
I am trying to use this code the transfer information across two scripts. From goblin.gd:
if melee_attack == true and player != null:
GlobalSignals.goblin_attack = true
print("Attack")
$AnimatedSprite2D.play("Attack")
goblin_attack_cooldown = false
$"Goblin Attack Cooldown".start()
player_chase = false
$"Run Animation Cooldown".start()
melee_attack = false
To player.gd:
func enemy_attacked():
if GlobalSignals.goblin_attack == true:
goblin_damage = true
func take_goblin_damage():
if goblin_damage == true:
$"Goblin Animation Wait".start()
func _on_player_hitbox_body_entered(body: Node2D) -> void:
if body.has_method("goblin"):
enemy_inattack_range = true
func _on_player_hitbox_body_exited(body: Node2D) -> void:
if body.has_method("goblin"):
enemy_inattack_range = false
func _on_goblin_animation_wait_timeout() -> void:
if enemy_inattack_range == true:
health -= health - 5
print(health)
GlobalSignals.goblin_attack = false
So I know that the line of code on goblin.gd is being read adn my character is doign the attack animation, but for some reason the information isn't being transferred to the globalsignals script as "global_signals works" isn't being printed, nor is the health on player.gd script.
All 3 scripts are on the scene being laoded, so I don't know what's wrong, Any help will be appreciated :pray
