YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Script assets returned by tag_get_asset_ids unable to execute #7598

Open gm-bug-reporter[bot] opened 1 month ago

gm-bug-reporter[bot] commented 1 month ago

Description

In my project I have a bunch of scripts that are all tagged that I want to loop over and execute them. In GameMaker LTS version this works perfectly fine. I get them with tag_get_asset_ids("tag", asset_script); and then iterate over them and run them.

For whatever reason in the current version of GameMaker the scripts do not run. You can step into them with the debugger but they exit before the first line of code in the script is executed.

The weird part of this bug is that in my main project I do this process many times and sometimes it works and other times it does not work. So is there times in the runtime where the script isn't initialized and then later into the game running it becomes initialized?

Steps To Reproduce

  1. Open the included project.
  2. Run it and observe the console. The project is attempting to run a script that prints "Script ran" but as you can see in the console it does not run the expected number of times.
  3. Be sad as your scripts didn't execute.

Which version of GameMaker are you reporting this issue for?

IDE v2024.8.1.171 Runtime v2024.8.1.218

Which operating system(s) are you seeing the problem on?

Mac 14.5

Which platform(s) are you seeing the problem on?

GX.games, macOS

464b555d-775c-4423-8389-53a250cb7d8f

RobertCordingly commented 1 month ago

Work around. So if you get the ID of a script with tag_get_asset_ids("a_tag", asset_script); and then find the name of the script with script_get_name(id), and then find the ID of the script with asset_get_index(name), then the script can be executed.

my_scripts = tag_get_asset_ids("a_tag", asset_script);
my_scripts[0](); //Does not work

var script_name = script_get_name(my_scripts[0]);
var real_asset_id = asset_get_index(name);
real_asset_id(); //Works!
RobertCordingly commented 1 month ago

This script basically fixes the issue:

function tag_get_asset_ids_fixed(tag, asset_type) {
    var data = tag_get_asset_ids(tag, asset_type);
    var aa = array_length(data);
    for (var i = 0; i < aa; i++) { 
        data[i] = asset_get_index(script_get_name(data[i]));
    }
    return data;
}