Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(4 edits)

I was hitting this same problem and spent several hours debugging it. What I found is that for some reason, calling the function delegate from the global variable "room_pack_eval_script" seems to break the scoping of "self".  If you step along the function calls from the beginning of the instance being created, "self" continues to reference the instance we want to modify up until we call "room_pack_eval_script".  I was able to get it working, simply by replacing the delegate call to a direct call of the function itself.    It seems like there's no reason that it SHOULDNT work as intended, but this is likely the fault of a bug in GML.

this doesn't work:

globalvar room_pack_eval_script; room_pack_eval_script = txr_eval_script;
function txr_eval_script(_code, _context) {
    var _pg = txr_compile(_code);
    if (_pg != undefined) txr_exec(_pg);
}
//GMRoomPack.gml
function room_pack_raw_run_cc(l_ccRaw, l_ccPath) {
   room_pack_eval_script(l_ccRaw, l_ccPath);
}

this does:

globalvar room_pack_eval_script; room_pack_eval_script = txr_eval_script;
function txr_eval_script(_code, _context) {
    var _pg = txr_compile(_code);
    if (_pg != undefined) txr_exec(_pg);
}
//GMRoomPack.gml
function room_pack_raw_run_cc(l_ccRaw, l_ccPath) {
   txr_eval_script(l_ccRaw, l_ccPath);
}

Doing room_pack_eval_script = method(undefined, txr_eval_script) might help..?

Or changing the line to be

var _m = method(undefined, room_pack_eval_script);
_m(l_ccRaw, l_ccPath);

Usually GML only binds self for functions when using v = function(...){...}

What an odd quirk, that totally works! You are an absolute hero for tracking all this stuff and replying.

Usually GML only binds self for functions when using v = function(...){...}

So then, what I don't understand is why THIS doesn't work.

globalvar room_pack_eval_script; room_pack_eval_script =  function(_code, _context) {
    var _pg = txr_compile(_code);
    if (_pg != undefined) txr_exec(_pg);
};
function room_pack_raw_run_cc(l_ccRaw, l_ccPath) {
    room_pack_eval_script(l_ccRaw, l_ccPath);
}

Swapping the function call here, with the method version you describe does indeed fix it.  But just having the inline v=function(){} here still results in Self being unbound.  I'm still pretty new to GML, thanks for taking the time to answer!

Also just gotta say thanks for making (and supporting) all these great extensions.  TXR is crazy and the kind of thing that would give me a cold sweat just thinking of planning/building in any language.