You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
changed the title
Instances: element_id
In-Game: Add a new "element_id" variable to instances on a room layer
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):
It can be shortened in broadcast event a little
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:
https://manual.gamemaker.io/monthly/en/The_Asset_Editors/Sequence_Properties/Broadcast_Messages.htm
The text was updated successfully, but these errors were encountered: