how connect buttons to event-bus singleton?

boruokboruok Posts: 1Member
edited October 17 in Programming

https://youtu.be/cSn8jeheG0E?t=2799
i've watched godotcon2019 where they talks about event bus, you just put all your signal intro one singleton script.

main.gd

extends Node

func _ready():
    events.connect('button_pressed', self,'_on_Event_button_pressed')

func _on_Event_button_pressed(name):
    print(name)

events.gd - singleton

extends Node

signal button_pressed(name)

button.gd - have multiple buttons in a scene what shares that script

extends TextureButton

func _ready():
    events.connect('button_pressed', self, '_pressed')

func _pressed():
    events.emit_signal('button_pressed', name)

well, method works , but i catch multiple errors everytime when i press:

E 0:00:02:0401   Error calling

  <C Source>     core/object.cpp:1238 @ emit_signal()
  <Stack Trace>  button.gd:11 @ _pressed()

https://godotforums.org/uploads/editor/wp/tqht0qlupn9z.zip

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file