Replies: 3 comments 3 replies
-
@upost we have Godot groups support. What would be the difference between the described EventBus and using groups? We already have blocks for calling a function in a group. The way to subscribe is by adding the node to the group. For example in the top-down spaceship demo: |
Beta Was this translation helpful? Give feedback.
-
The difference is that calling a method does not reflect the publisher subscriber pattern, where the sender does not need to know who will process a message, does not need to wait for completion for example and so on. There are quite some differences, I mean there's a reason for having MessageQueues present everywhere in the industry ;-) And for educational purposes, I'd like to teach it to the kids the right way from the start - and they already know it from Scratch! If you like I can try to implement this idea. |
Beta Was this translation helpful? Give feedback.
-
For the record, here are the commits that removed the previous iteration, which looked very similar to what you want: |
Beta Was this translation helpful? Give feedback.
-
Dear team,
Scratch has a message system which allows objects to be losely coupled by just sending or receiving messages. This is also a widespread software design pattern (publisher-subscriber) and I find it very helpful also in game development and very easy to understand for kids who just started learning how to code.
There even is a plugin for Godot:
https://godotengine.org/asset-library/asset/3477
That said, it's so easy you don't need a plugin. Defining events can also happen in a preloaded node named
Eventbus
like so:extends Node signal started signal levelup signal died ...
To send an event from anywhere:
Eventbus.started.emit()
To listen to an event in any other node script:
`Eventbus.started.connect(_on_started)
func _on_started():
...
`
What do you think about adding this to block coding like in Scratch, hiding the need to create the Eventbus node and the connect calls, just having one block which sends messages and one reacting on receiving a certain message? (and of course required stuff like creating/editing message, like variables)
Thanks for reading!
Uwe
Beta Was this translation helpful? Give feedback.
All reactions