YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
22 stars 8 forks source link

Broadcast Messages could have a new function to send messages receivable by all asset types #6153

Open mmMarzban opened 3 months ago

mmMarzban commented 3 months ago

Is your feature request related to a problem?

There are things in the game that when happen, multiple objects or assets get involved with. For example suppose we have a player object that when collects the 100th coin, they will get an extra life and it must be reflected in the HUD, and some kind of particle effect must be shown as a sign of celebration.

In Godot and Unity, users implement all the process easily by using signals or events. However in GM, we don't have such a pub-sub system and therefore we have to hard-code all the stuff or declare a global variable or find other workarounds to get the thing done in different objects.

Although currently we do have Broadcast Messages in GM, However it it is dedicated only to sprites and sequences. (and thus has little use)

Describe the solution you'd like

What if we had Broadcast Messages as a function (e.g. send_broadcast_message(string)) and it was receivable by anything?

I mean in the above example when the player hits the 100th coin we could write the following in the Collision Event: send_broadcast_message("another 100 coins collected!");

And then we would be able to receive the message in any other objects and act accordingly. For example in the Broadcast Event for the HUD object:

if event_data[? "event_type"] == "object event" { if event_data[? "message"] == "another 100 coins collected!" { animateHUD(); } }

And for other objects alike.

Describe alternatives you've considered

No response

Additional context

No response

ParodyKnaveBob commented 3 months ago

For what it's worth, this is where User Events save the day:

scr_game_init

#macro  UE_100COINS     0

Collision Event

instance_destroy(other);
if (++tally_coins == 100) {
    with (all) {
        event_user(UE_100COINS);
    }
    tally_coins = 0;
}

o_hud's User Event 0

/// @desc 100 Coins
animate_HUD();

This does currently limit broadcast messages to 16, but the ability's always been there. This is tantamount to preparing every single instance with 16 blank, enumerated methods, ready to go.

YYDan commented 1 month ago

Note that 7486 has a fair bit of extra info that should be considered when planning this request.