Signal Binding Inconsistency
Asked Answered
E

6

0

This works perfectly:

# Signal
signal blanksAdded (blanks, influences);
# Emit
func Add_Blanks (blanks:Array[Vector2i], influences:Array[Biome]):
	blanksAdded.emit (blanks, influences);
# Connect
func _ready():
	GlobalData.blanksAdded.connect (SpawnInBlanks);
# Callable
func SpawnInBlanks (posArray:Array[Vector2i], influences:Array[GlobalData.Biome]): # function body

This runs, but with errors:

# Signal
signal timePassed (timeSteps);
# Emit
func PassTime (timeSteps:int):
	timePassed.emit (timeSteps);
# Connect
func _ready():
	GlobalData.timePassed.connect (RoamCheck);
# Callable
func RoamCheck (timeSteps:int): # function body

Error:

E 0:00:02:0384   GlobalData.gd:189 @ PassTime(): Error calling from signal 'timePassed' to callable: 'Node2D(BirdHandler.gd)::MoveUp': Method expected 0 arguments, but called with 1.
  <C++ Source>   core/object/object.cpp:1140 @ emit_signalp()
  <Stack Trace>  GlobalData.gd:189 @ PassTime()
                 DirectionalKeyControl.gd:23 @ Move()
                 DirectionalKeyControl.gd:12 @ CheckMove()
                 DirectionalKeyControl.gd:8 @ _process()

This is the error when I change the last # Connect code to:

func _ready():
GlobalData.timePassed.connect (RoamCheck.bind (timeSteps));

Error:
Parser Error: Identifier "timeSteps" not declared in the current scope.

Any help would be appreciated. 🍀

Epaminondas answered 3/3 at 12:58 Comment(0)
E
0

Epaminondas The error does not seem to be located in the part of the code you are showing. I suspect the implementation of the RoamCheck function, but without seeing the code that is impossible to say

Extract answered 3/3 at 13:27 Comment(0)
O
0

Epaminondas Looks like the signal is not connected to the method you expect it to be. Hard to debug without seeing the whole context. Try to make a MRP and post it.

Oriel answered 3/3 at 13:27 Comment(0)
E
0

Extract

In that case, could it be because of how I was using Dictionaries in the RoamCheck? I was iterating over a dictionary structured like this:

int : [Enum, Vector2i, Node2D]

The Node2D is a reference to a spawned object, and I was using it to change it's position and modulate. Is it okay to do that? Thank you for you input.

Epaminondas answered 4/3 at 0:3 Comment(0)
E
0

Epaminondas Unlikely. Its probably some trivial mistake somewhere. Impossible to say without seeing the code. My bet is still on the implementation of the RoamCheck function. But it is also possible that Importance came up with the right idea. We are only guessing here.

Extract answered 4/3 at 7:58 Comment(0)
E
0

Thank you for the answers. I'd love to share the code, but it's a bit of a mess.

I'm taking off the features affected by this problem for now, but I'll check back when I come back to it down the road.

Epaminondas answered 16/3 at 4:6 Comment(0)
N
0

GlobalData.gd:189 @ PassTime(): Error calling from signal 'timePassed' to callable: 'Node2D(BirdHandler.gd)::MoveUp': Method expected 0 arguments, but called with 1.

In your birdhandler script you connected the timePassed signal to the MoveUp function. timePassed passes the timeSteps as argument, but MoveUp hasn't any arguments defined. Well that's how I understand the error message.

Now I realize that I basically wrote the same thing Godot spit out. 😛

Nimiety answered 16/3 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.