Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-Game: Add a new "element_id" variable to instances on a room layer #9201

Open
gnysek opened this issue Jan 29, 2025 · 1 comment
Open
Labels
feature request New feature (or a request for one)

Comments

@gnysek
Copy link
Contributor

gnysek commented Jan 29, 2025

Is your feature request related to a problem?

Currently, there's no easy way to find element_id of current instance. It could be useful in Broadcast messages, where we want to execute something only for instance, that sends broadcast (for example others have same sprite, but image_speed is 0).

Currently, way to get current element id is kinda long, and not efficient when executed every frame (but if element id doesn't change even when changing layers, then this could be minimized to create event only):

element_id = undefined;
var elems = layer_get_all_elements(layer);
for(var i = 0, n =array_length(elems); i < n; i++) {
    if (layer_get_element_type(elems[i]) == layerelementtype_instance) {
        if (elems[i] == event_data[? "element_id"]) {
            element_id = elems[i];
            break;
        }
    }
}

It can be shortened in broadcast event a little

if event_data[? "event_type"] == "sprite event"
{
    switch(event_data[? "message"])
    {
        case "BroadcastMessage":
        {
            if (layer_get_element_type(event_data[? "element_id"]) == layerelementtype_instance) {
                if (layer_instance_get_instance(event_data[? "element_id"]).id == id) {
                    // this is exactly this instance
                }
            }
        }
    }
}

Describe the solution you'd like

Add new built-in variable for instances, named element_id which would return current element id on layer.

Describe alternatives you've considered

Alternatives are described in both code examples.

Additional context

Broadcast message in sprite:

Image

https://manual.gamemaker.io/monthly/en/The_Asset_Editors/Sequence_Properties/Broadcast_Messages.htm

@gnysek gnysek added the feature request New feature (or a request for one) label Jan 29, 2025
@KamilWdowczyk
Copy link

KamilWdowczyk commented Jan 29, 2025

Strange behavior that the brodcast message is propagated to all instances. It seemed to me that brodcast is local. This even occurs as instances have different sprites.

@YYDan YYDan changed the title Instances: element_id In-Game: Add a new "element_id" variable to instances on a room layer Jan 29, 2025
@stuckie stuckie moved this from Triage to Backlog in Team Workload Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature (or a request for one)
Projects
Status: Backlog
Development

No branches or pull requests

2 participants