I know when I receive any message exists as well as the message block but those can be very buggy and most people likely don’t know that the message block even exists
So instead of all messages how about making it so you can put a list in the message input
The block would listen for messages of the names in the List, if it gets one then it will run the hat
Making multiple hats with identical code underneath isn’t a workaround because you could trigger 2 different ones at the same time
Yes but that involves the (message) block that’s not known by a lot of people, as well as if you broadcast any message during the script than it completely stops if it’s not listening for it. This block wouldn’t do that just like the other message blocks
The data variable is the message name. If you also send data, then the data variable will be a list, with the first item being the message name, and the second being the data that was sent.
I never knew that..
Still the solution isn’t fully airtight, still if you broadcast another different message that it isn’t listening for than it stops the script, what if you are broadcasting a message without data and some with data
Snap! has two ways of handling overlapping events. The default way (inherited from Scratch) is that a second event restarts the script, dropping the processing of the first event in the middle. This has the obvious disadvantage that it can leave data structures in an inconsistent state, but it has the advantage of prompt handling of events, which is especially important for timing the playing of music. The second way, which you get by choosing "Thread safe scripts" in Settings , just drops the second event, so it never gets handled at all, but any event that starts is guaranteed to finish.
Of course neither of these is the Official Right Thing. I've long been advocating for a real event queue, so all events are handled in the order received, not necessarily promptly if users' event handlers are slow. I would like any of the three strategies to be choosable on a per-script basis, not as a global option.
Jens doesn't exactly argue against this, iirc, but it isn't a priority for him. Maybe he worries that it would slow things down too much.