Cant get a signal to connect through code

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

I have two scripts ones a class_name called Actions, and the other is a scene with a script that does some ui updates, in the class script I have a signal and a function that gets called when doing an action, in the function I emit a signal, in the other script i connect the signal with self.connect(“ui_update”, self, “update_ui”) but this never happens because the function inside that script never runs

func _ready():
	self.connect("ui_update", self, "update_ui")

func update_ui():
	print("ui is updating")

That is the script what I want to run a function

class_name Actions

signal ui_update

func attack(attacker_inventory, target_inventory, move):
	#print(str( + " used " + str( + " " + str((move)))
	var attacker = attacker_inventory[0]
	var target = target_inventory[0]
	var new_text = ( + " attacked with " +
	#text_scroller(new_text) # UI will become usless unless I change how the ui is controlled
	var data = recieve_damage(move,attacker,target)

and this script I simply emit the signal but nothing works, either the signal doesnt get emitted or the signal never actually connects and I have to do it this way since this class script isn’t in a scene

Looking in the debug box it says its a nonexistent signal so the signal doesnt exist yet, how can I go around this?

Dragon20C | 2021-05-19 07:25

:bust_in_silhouette: Reply From: magicalogic

That is because the signal isn’t a property of that scene with the receiving method.
You have to connect it in the Actions class like this:


where would I put it, in the ready function Does the class still work with the ready function?

Dragon20C | 2021-05-19 07:52