How do you keep track of signals and variables being passed between multiple scenes/files?

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

Hi! I’m new to godot, and I’m going through the excellent Tank Battle tutorial series.

One thing that confuses me is keeping track of signals and variables between multiple files. For example, this course teaches how to create self-guiding misslie that automatically pursues it’s target(player). When it’s all done, here’s what it takes to pass the player object to the missile:

  1. EnemyTank has a collision shape that sends it a signal when player enters it’s radius, setting the “target” variable(that I now need to pass to the missile).
  2. When it’s time to shoot a missile, EnemyTank calls a shoot() method of Tank(it’s parent class), passing it the “target”.
  3. Tank emits a signal telling the level Map to spawn the Bullet(because bullet needs to be parented to the level, not to the tank), passing “target” along.
  4. Map spawns the Bullet, and calls a method on the Bullet object, passing the “target” to it.
  5. And then Bullet finally uses the “target” to steer towards player.

I wanted to ask - is this kind of thing normal in godot? If yes, then how can I manage this complexity, or document it somehow? Because I can’t imagine how a different programmer(or even me in a few months), looking at a Bullet script and trying to figure out where does the “target” come from, would untangle all this. Tracing things backwards would be so hard, there are so many scripts, and no obvious way to find out what calls the method I’m looking at.

Extensive commenting could work, but doesn’t seem ideal, I’d have to explain this whole thing in 5 places in my code to make it clear where does the “target” object come from, where it’s going, and why.

Any advice?

:bust_in_silhouette: Reply From: lofi

delibering bullets can get cumbersome, u wont save sending some signals here and there, point 1 and 2, instead collision shape send enemytank a signal, why not sending it directly to tank passing where target is and which tank detected it, or even why not sending it directly to map spawner?; and then if you dont like signals u can use setget instead.

examples are good to grasp ideas but then do whatever u want if it works for you