Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

GMRoomPack

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

room_pack_load_map error, expecting a number

A topic by ProfaneArtillery created Mar 10, 2021 Views: 59 Replies: 1
Viewing posts 1 to 2
(3 edits)

Hi! First of all I'd like to thank you for this extension; the possibilities this introcudes into my project have re-lit my enthusiasm to work on it again~! I have run into a small issue though, but it's not a big deal as I'm still wrapping my head around a few things elsewhere so no rush- 

Right.
I can load individual rooms from a .json fine, no issue; but when it comes to loading specific and or random rooms from a map I'm entirely lost. I'm 95% sure it is something I'm doing wrong; but no matter how much I look at the cheat sheet documentation I can't figure out quite what it is.
I've included my code and the resulting error; any help would be greatly appreciated. I've had this issue crop up throwing an error regarding expecting a number from roomWidth and roomHeight also.

var json_rooms = room_pack_load_file( _dir + "rm_seg_1.json", 0, 0, room_pack_flag_instances );
// pick a random room name from the map:
var name = ds_map_find_first( json_rooms );
repeat( irandom_range( 0, ds_map_size( json_rooms ) - 1 ) ) {
    name = ds_map_find_next( json_rooms, name );
};
// and load that:
room_pack_load_map( json_rooms[ ? name ], 384 / 2, 0, room_pack_flag_instances );
// and when you're done:
ds_map_destroy( json_rooms );
Developer

room_pack_load_file runs room_pack_load_map and returns whether succeeded (as per documentation).

If you have packed all of your rooms into a file, you’d want to load it up like

var _buf = buffer_load("rooms.json");
if (_buf != -1) {
    var json_rooms = json_decode(buffer_read(_buf, buffer_string));
    // rest of the code you have
    buffer_delete(_buf);
}

If you only have a single room in that file, then just calling room_pack_load_file will suffice.