• Godot Help
  • Why can't my script receive more than two signals?

Hi everyone

I'm making a game that has two squares and a rectangle. The colour of the squares and rectangle changes between red and green.

I want the squares to disappear if you click on them while they are the same colour as the rectangle.

I have a green square sprite, green rectangle sprite, red square sprite and red rectangle sprite.

When each sprite is loaded, the program sends a signal to the square script so it knows what colours the squares and rectangle are.

This is my code to detect when the squares are clicked on:

The problem I'm having is that the script won't receive more than two signals at a time.

It'll either receive the _on_Zone signals or the _on_Square signals, but not both. It just switches to receiving the other signal when I try to set it to receiving both.

Does anyone know how I can fix this?

Thanks

The first two functions are not connected (or the last two on the other screenshot). You have to be sure when you connect them, that you use the correct object and function name.

You can access this on the tab on the far right of the editor under Signals and click advanced and make sure you didn't make a mistake.

    cybereality

    That's the problem. I can't connect all four at the same time. If I connect the Zone functions, it'll disconnect the Square functions. If I connect the Square functions, it'll disconnect the Zone functions.

    I don't know why it's doing this :S

    A Signal only connects one event to one function. However, you can send parameters to the functions to do different things.

    Probably what you want is to get the overlap (I assume this is an Area) so area_entered (for example) and then send the name of the object or an id number or something.

    This would require a custom signal. If you want to use the built-in ones then just add some logic in the function.

    A Signal only connects one event to one function.

    This is not correct. A signal can be connected to as many functions as you want.

    That's the problem. I can't connect all four at the same time. If I connect the Zone functions, it'll disconnect the Square functions. If I connect the Square functions, it'll disconnect the Zone functions.

    And this sounds impossible. Adding a new connection should newer remove an existing one. I suspect something is going wrong here on a more fundamental level. Maybe a misunderstanding on how the editor or signals work.

    It would help if we could see the node structure (the scene tree).

      Zini This is not correct. A signal can be connected to as many functions as you want.

      If you do it in code yes. I think if you do it in the editor interface you can only specify one attachment.

      • Zini replied to this.

        cybereality Nope. Editor can do multiple connections per signal too (at least Godot 3 editor can)
        .!

          Hmm.. okay. Then maybe the OP is overriding the signal instead of creating a new one?

          • Zini replied to this.

            Zini Editor can do multiple connections per signal too

            I experimented with that. It works, but it could be confusing, especially to a beginner.

            This is how I'm connecting the signals.

            I click on the red squareIsGreen() icon.

            I choose Sprite, then click connect.

            When I go to the script attached to Sprite, the on_Square functions are connected, but the on_Zone functions get disconnected.

            Is there another way to connect the signals?

            How do you connect onZone functions? Are both squares and the zone all instances of the same scene?

              xyz

              I click on the red icon.

              Then choose Sprite and click connect.

              Godot will then disconnect the on_Square functions and connect the on_Zone ones.

              This has probably something to do with scene structure. It'd be best if you could make a minimal project and attach it here so someone can give it a look.
              With your screenshots you didn't provide enough information. We don't see the exact scene structure, we don't see which scripts are attached to which nodes and we don't see full paths/names of signal callbacks. With all that information missing, figuring out what's wrong is a guessing game.

                OofStatement

                I just realised "Sprite" was the Zone only. I confused myself by not having a SquareSprite and ZoneSprite. Gonna try fix it myself.

                • xyz replied to this.

                  OofStatement
                  There are quite a few issues.
                  in scene square:

                  • node Square has the signal visibility_changed() connected to a missing method _on_Square_visibility_changed(). Godot issues an error in the debugger exactly describing the problem.

                  in scene Gameplay:

                  • in script QuestionZone.gd you declare two signals zoneisGreen and zoneisRed. In the same script you try to emit those signals using names zoneIsGreen and zoneIsRed (uppercase "i" instead of lowercase) so signals are not found. Godot issues "non-existing signal" errors in the debugger specifying which signal names are non-existing.

                  • there are couple more signal connections from Zone node to non-existing methods but I'll let you figure that out yourself from the debugger error messages. They clearly state the problems.

                  However, all 4 signals you were talking about are in fact connected. You can see this by looking at the signal connections in the inspector/node tab where everything is listed. If connection is listed there then it exists. Note that even though a connection exists the callback function the signal is supposed to call still may be missing (as you can see in the first problem I described above).

                  What confused you was that little green arrow/door icons were missing in the code editor. That's because you have the same script attached to nodes in different scenes. When you look at the code from within a particular scene it will show you icons only for connections in that scene, i.e. it shows those icons in context of the scene you're currently editing. I suggest you avoid having the same script attached to nodes in different scenes, at least until you get better understanding of how signals operate.

                  In general your scene structure looks overcomplicated for such a simple logic. Poor scene organization resulted in convoluted signal connections that are hard to follow. You should rethink it and simplify the system.