room_add/duplicate issues

philis401

Member
so working on a game where rooms can be made ingame. First room made works fine, but when making another room using same code, it just shows up grey (default blank room im assuming). The new room does return a different room id and i am able to switch between rooms (each room has a "controller" object created and to test i have a message pop up with the id of room they are in and both returns an actual id.)



Also just read that rooms added in room_add cant be deleted (which isnt ideal) so i thoguht i'd just create a duplicate of an empty room and change stuff with code. However, even with the id given by room_duplicate i cant seem to do anything from code above (i simply just changed room_add to room_duplicate, assuming all the room_set_... codes will change the duplicated room)., but the room i got to is blank like the empty room i duplicated even though i have code that changes background and renders some sprites and even have camera and views setup.. How do I properly actually use any of these? Am I missing something?
 

TheouAegis

Member
Are you calling the room_set codes OUTSIDE the room you targeted? or did you go to the room first and try to change the room while you're in it?
 

philis401

Member
Are you calling the room_set codes OUTSIDE the room you targeted? or did you go to the room first and try to change the room while you're in it?
it is outside. I have a room specifically for "generating" new room. Once it sets up all the views and cameras and instances, it then goes to the new room. It works for the first room, but the subsequent other ones do get made but dont seem to go through the other room_set codes.
 

TheouAegis

Member
Odd. I would say post your code, but first try to debug it by making sure that you are actually targeting the correct rooms when trying to set up the subsequent rooms. I mean, you would expect to at least have the wrong room set up inside one other room, but just make sure you aren't, for example, setting the first room over and over and over.
 

philis401

Member
Ok getting weird problems now too. Ive tried creating blank rooms and a "transition" room to go to before going to the generation room (with a few seconds before transitioning). Had same results but then for some odd reason, id get the blank room issue on the first generated room, but if i deleted those empty rooms/transition rooms, it would work o.o (the idea for the blank rooms were to copy em and use that id returned for the room_set... codes, but when changing back to room_add, no longer using those blank rooms, i still get a blank room until i deleted tose blank rooms in the asset browser despite them no longer being used in code.)

Resetting cache and stuff didnt help. And now, the first room is blank, but second room works. And then subsequent ones wont. The main code hasnt changed much, all ive done was swtich room_add and duplicate around.

Anyway here are the codes

Code below is in the creation event of the room that is creating new rooms (well room creating is in the constructor). Room is called rmGenOverworld and its empty, only containing code in its create event. (tried using an object just to see, but same results regardless)
GML:
var w,h,inc,roomid;
w = irandom_range(10,50);
h = irandom_range(10,50);
inc = 150;
//oGame is the "main controller".   Code below creates a new constructor and stores its id in an array.  Room_add/set codes are in the Overworlds constructor.
with(oGame) {
    game.cur_state = cursor_state.draw_tool;
    overworlds.Add(new Overworld(w,h, inc));
 
}

//libsize is the length of array.  libsize is ini at 0, so below should be the "first" room.  roomid var shud have the roomid stored in the library
roomid = oGame.overworlds.lib[@ oGame.overworlds.libsize].roomid;


with(roomid)
{
    //this creates a variable referncing to the oGame's library for the new room's controller object to use
    overworld = oGame.overworlds.lib[@ oGame.overworlds.libsize];
 
    with(overworld)
    {
        //code below stores info in variables so rooms controller object can render the "map", so before we even load into the new room, it should already hhave the data to render a map
        PopulateGrid();
        var rand = irandom_range(region_ref.plains,region_ref.tundra);
        repeat(3) {
            GrowLand(irandom(map_w),irandom(map_h),.75,rand);
        }
        rand = irandom_range(region_ref.plains,region_ref.tundra);
        repeat(2) {
            GrowLand(irandom(map_w),irandom(map_h),.5,rand);
        }
        rand = irandom_range(region_ref.plains,region_ref.tundra);
        repeat(2) {
            GrowLand(irandom(map_w),irandom(map_h),.25,rand);
        }
    }
}

with(oGame)
{
    overworlds.Update();//updates the size of the array containing constructs of Overworlds
    room_goto(overworlds.lib[@ oGame.overworlds.libsize - 1].roomid);
}
and below is part of the cosntructor code
GML:
    roomid = room_add();
    room_set_width(roomid,map_w * tile_inc);
    room_set_height(roomid,map_h * tile_inc);
    room_set_viewport(roomid,0,1,0,0,oGame.camera.window_width,oGame.camera.window_height)
    room_set_camera(roomid,0,oGame.camera.cam);
    room_set_view_enabled(roomid,1);
    room_instance_add(roomid,0,0,oOverworld);
    room_set_persistent(roomid,1);
Once we load into the rooms, the room's controller object calls this at creation:
GML:
static CreateTileLayer = function () {
            with(tilelayer)    {
                if(!layer_exists(layid0))
                layid0 = layer_create(1,"tiles");
                if(!layer_exists(layid1))
                layid1 = layer_create(-1,"inst");
                if(!layer_background_exists(layid0,backid))
                backid = layer_background_create(layid0,sprOcean_tile);
                layer_background_htiled(backid,1);
                layer_background_vtiled(backid,1);
            }
    }
Was hoping to be able to do all this dynamically, but my other solution i have yet to try is just have a premade rooms with max size the maps can be, have it set to persistent, then disable it when im ready to "generate" new maps. If it works, at least i should save up on some memory :u

I did planned for a max limit number of maps, havent tried creating all of them first, but was hoping i cud try to be more efficient with memory because i think it'd be a waste if for some reason the player only used like one or two of them.
 

TheouAegis

Member
//libsize is the length of array. libsize is ini at 0, so below should be the "first" room. roomid var shud have the roomid stored in the library roomid = oGame.overworlds.lib[@ oGame.overworlds.libsize].roomid; with(roomid)
Is roomid an object_index or instance id? You can only use with() on objects or instances, not rooms, if that's what's going on there. I didn't look over the full code yet, just noticed this lone and it set off alarms. lol
 

philis401

Member
Is roomid an object_index or instance id? You can only use with() on objects or instances, not rooms, if that's what's going on there. I didn't look over the full code yet, just noticed this lone and it set off alarms. lol
Really? Coz i was able to store the "overworld" variable to the first created room. It worked when in the create event of controller object i accessed the variable i gave to the room by using with(room)...idk, if thats the case then i have to try something else. Thinking of scrapping this idea as returning the game to a previous working state now has the weird issue where first room is blank, second is working , rest are blank again despite it being the same code when it did work for the first room. Thanks for trying to help, appreciate it, but i think im just gonna have to scrap and redo everything relating to the map generation.
 

kburkhart84

Firehammer Games
Really? Coz i was able to store the "overworld" variable to the first created room. It worked when in the create event of controller object i accessed the variable i gave to the room by using with(room)...idk, if thats the case then i have to try something else. Thinking of scrapping this idea as returning the game to a previous working state now has the weird issue where first room is blank, second is working , rest are blank again despite it being the same code when it did work for the first room. Thanks for trying to help, appreciate it, but i think im just gonna have to scrap and redo everything relating to the map generation.
Yes, really. with() is for objects, instances, and structs. It is likely that the room id happened to be the same as some object id by sheer luck and so the with() statement worked, but you would be depending on undocumented behavior if you kept that in there.
 
Top