In the documentation, it says that various arguments can be passed in user-defined signals (weapon type, damage, etc.), but when I try this, I only get errors. So right now, I have this. Basically it is just emitting a signal to add an item to an ItemList node:
The "item" (an Area):

extends Area
class_name Items

export var item = "name"

signal add_item

func _on_Area_body_entered(body):
	if body.name == "kiyuga":
		print("AddItem")
		emit_signal("add_item")
		queue_free()
		pass

And this is the "inventory" where the thing is going:

onready var testInventory = $PauseTabs/Equipment/GridContainer/TabContainer/ItemList
...
func _on_Area_add_item():
	testInventory.add_item("Name") #understanding that it's just a placeholder name and I'm not expecting the actual name

Which is great and all, except I'd rather not have separate scripts for every single item. But when I try to do something like

emit_signal("add_item", item)
connect("add_item", self, "_on_Area_add_item", [item])
func _on_Area_add_item():
	testInventory.add_item(item)

I get errors and nothing happens. I am very confused. What am I missing?

  • Instead of:

    signal add_item
    ...
    emit_signal("add_item", item)
    ...
    connect("add_item", self, "_on_Area_add_item", [item])
    ...
    func _on_Area_add_item():
        testInventory.add_item(item)

    try this:

    signal add_item (item)
    ...
    emit_signal("add_item", item)
    ...
    connect("add_item", self, "_on_Area_add_item")
    ...
    func _on_Area_add_item(item):
        testInventory.add_item(item)

    The signal arguments can either be declared in the signal declaration or the connect call, but I don't think they can be in both places..

Instead of:

signal add_item
...
emit_signal("add_item", item)
...
connect("add_item", self, "_on_Area_add_item", [item])
...
func _on_Area_add_item():
    testInventory.add_item(item)

try this:

signal add_item (item)
...
emit_signal("add_item", item)
...
connect("add_item", self, "_on_Area_add_item")
...
func _on_Area_add_item(item):
    testInventory.add_item(item)

The signal arguments can either be declared in the signal declaration or the connect call, but I don't think they can be in both places..

    DaveTheCoder

    It works, but I still get this:

    E 0:00:20.573   connect: In Object of type 'CanvasLayer': Attempt to connect nonexistent signal 'add_item' to method 'CanvasLayer._on_Area_add_item'.
      <C++ Error>   Condition "!signal_is_valid" is true. Returned: ERR_INVALID_PARAMETER
      <C++ Source>  core/object.cpp:1468 @ connect()
      <Stack Trace> PauseMenu.gd:20 @ _ready()

    DaveTheCoder
    Yes. Emit_signal is coming from an Area script, and the connect/_add_item are in a CanvasLayer script. Picking up items littered around the level and putting them in an ItemList (Inventory in a Pause Menu).

    It's working and everything.

    Is there a way to get the parameter from the one function and use it in another?

    func _on_Area_add_item(item, type, icon, descr): #want to take this description
    	testInventory.add_icon_item(icon)
    	var description = descr
    
    func item_text_update(): #and put it here to update the item description
    	item_descr.bbcode_text = "d"
    
    func _on_ItemList_item_selected(index):
    	item_text_update()
    	item_popup.popup(Rect2(250, 250, 500, 524))
    	print("You selected an item")