#Problem with singals

1 messages · Page 1 of 1 (latest)

hardy peak
#

It doesn't matter how the node is added. But the signal must be defined in the node's script.

#

Also, are you adding this with a @tool script?

woeful igloo
hardy peak
#

If you are adding this node with add_child(). That means you are doing it while the game runs.
At that point you cannot connect the node from the editor.

#

Because it does not exist in the editor.

woeful igloo
#

so i have to make it with script?

#

documentation didn't teach me that yet 😔

hardy peak
#

I am not sure what you're trying rn.
But code only runs while the game is running. And changes that happen in the game do not affect your project. They stay in RAM

woeful igloo
#

that must not be the best way to do that tbh

hardy peak
#

You would have to connect them in code.

Like, if the script is in the glove:

func _ready():
  var player: Node = get_parent()
  glove_signal.connect( player.on_glove_does_the_thing ) 
woeful igloo
#

Now my code is like this

Glove Script

    state = "idle"
    var player: Node = get_parent()
    glove_signal_state.connect(player.get_glove_signal)

func _process():
[...]
    emit_signal("glove_signal_state",state)```

Player Script
    $StateLabel.text = state``` 
#

i'm getting Invalid access to property or key 'get_glove_signal' on a base object of type 'Window'. error

#

so i assume it wasn't possible to connect the signal

hardy peak
#

I think there are many issues here.
First this seems to be an autoload, so it is a child of the game window and not of the player. (well, it could be child of both)
Then the naming convention for the player signal leads me to believe that this function is not for what you want it to do

woeful igloo
#

wait what, child of the game window?

hardy peak
#

the error says the parent is of type Window.
The game window is also a node, the top one of the entire tree (not visible from the editor)

woeful igloo
#

oh ok

hardy peak
#

The only way to have a node that high up in the tree is to parent it to the root or to make it an autoload, so those are my suspects rn

woeful igloo
#

So, when i did

    add_child(glove)```
I turned this a node from the window?
hardy peak
#

i think you have it as an autoload too. So you have 2 in total

woeful igloo
#

Ok, now i need to find out whats autoload just a second

#

prob an option

#

from the editor

hardy peak
#

it would be in Project>Settings>Globals

woeful igloo
#

nono there are no autoloads

woeful igloo
hardy peak
#

the Debugger tab, specially the Stack Trace window, has more information during the crash. Try triggering it again and checking that