How to connect a signal using a function from another file?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

For example, I have a file called GameFunctions.gd

I can access all its functions by doing GF.myFunctionHere

Problem is, I’m trying to connect a signal outside of this file but using a function thats inside GF.

Example / Problem:

		temp_monster.connect("mouse_enter", self, "GF.MonsterHover")
		temp_monster.connect("mouse_exit", self, "GF.MonsterOut")

Obviously this won’t work, as the parameter is a string :stuck_out_tongue: Not sure if I’m having a brain fart, or just missing something stupid, thanks!

:bust_in_silhouette: Reply From: wombatTurkey

Hmm. I found a temporary solution. This is kind of annoying, but I mean, it works.

temp_monster.connect("mouse_enter", self, "MonsterHover", [temp_monster])
temp_monster.connect("mouse_exit", self, "MonsterOut", [temp_monster])

Then just use GF.call and pass the node as a parameter

func MonsterHover(node):
	GF.call("MonsterHover", node)

func MonsterOut(node):
	GF.call("MonsterOut", node)

If anyone has a better solution, please let me know and I’ll accept you as Best Answer

:bust_in_silhouette: Reply From: CowThing

Replace the self with GF. The second argument of connect is the target of the function.

temp_monster.connect("mouse_enter", GF, "MonsterHover")
temp_monster.connect("mouse_exit", GF, "MonsterOut")

This should be accepted answer.

splite | 2016-08-02 10:33