Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

GMRoomPack

Package GameMaker rooms and load them as you please · By YellowAfterlife

room-pack-eval with txr2 not working?

A topic by dreamsknight created Dec 13, 2020 Views: 438 Replies: 7
Viewing posts 1 to 4
Hello, I purchased the asset recently and everything is working fine except loading instance creation codes/variables.I used the txr2 method as per doc and I think it is saving the information right:
{
                    "name": "level0entrance",
                    "creationCode": "unlocked = true;\r\n",
                    "x": 1152,
                    "y": 480,
                    "obj": "par_room",
                    "propertyCode": "special_room_name = \"starting_room\";\r\n"
                },
But when I try to load a room I get this error :
ds_map_copy argument 2 incorrect type (string) expecting a Number (YYGI32)
 at gml_Script_txr_thread_create (line 19) -                ds_map_copy(locals, argd);
############################################################################################
gml_Script_txr_thread_create (line 19)
gml_Script_txr_exec (line 6) -        var th/*:txr_thread*/ = txr_thread_create(arr, argd);
gml_Script_room_pack_raw_run_cc (line 116) -        room_pack_eval_script(l_ccRaw, l_ccPath);
gml_Script_room_pack_raw_run_yy_inst_cc (line 140) -               if (l_rcc != undefined && l_rcc != "") room_pack_raw_run_cc(l_rcc, l_rname + ":Properties");
gml_Script_room_pack_raw_add_layer (line 275) -                                           room_pack_raw_run_yy_inst_cc(self, l_qinst);
gml_Script_room_pack_raw_run_impl2 (line 339) -               room_pack_raw_add_layer(l_lrs[|l_lrk]);
gml_Script_room_pack_load_map (line 64) -        room_pack_raw_run_impl2(l_map);
gml_Script_room_pack_load_string (line 86) -        room_pack_load_map(l_raw1, l_x, l_y, l_flags);
gml_Script_room_pack_load_file (line 104) -               var l_z = room_pack_load_string(buffer_read(l_buf, buffer_string), l_x, l_y, l_flags);
gml_Object_obj_generate_level0_Alarm_0 (line 3) - room_pack_load_file("TestRoom.json");
I really need to save instance creation code, is there a working way?Or am I doing it wrong?
Thanks
Developer

I expanded TXR at some point, changing how some functions work, so you would want to do

room_pack_eval_script = function(_code, _context) {
    var _pg = txr_compile(_code);
    if (_pg != undefined) txr_exec(_pg);
}
(3 edits)

Ok the error is gone and it kinda works now, but it loads the variables on wrong instances.
The saving seems fine, but it loads the variables on random instances of the parent object.I believe I am doing something wrong, where exactly am I supposed to put that code?I put them on a parent object, as the it didn't work in the create event of a controller object.(I use the *variables* tab on objects in the room editor to assign some of them names as *secret_boss_room*, I haven't tried the creation code maybe it works better I will try it today)

Edit: Ok when I assign the variables through creation code it works just fine!It is the PreCreate/variable definition event that doesn't seem to work.Now that I think about it, I am not even sure if it is supposed to work with those.I am more than happy with creation code, just leaving this here in case it is a bug and you may want to fix it in the future.

Developer

If what you are doing works in regular (non-roompacked) rooms, please send me a sample project via email/discord/etc.

Ah I see, thanks a lot!

(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);
}
Developer

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.