Cloned (dynamic objects) rooms are mis-behaving

I am experimenting with cloning rooms using the Dynamic Objects extension by Jesse McGrew.
It’s nearly working but I’ve got some really weird problems with the connections between cloned rooms.

Before we go any further… Yes, I know, dynamic objects, do I really need them? Probably not. I was just messing about and then this potential bug started bugging me and I’m curious to know what is happening!

I’ve assumed that with Dynamic Objects you can create as many clones of the same ‘empty’ room as you like and then link all the clones into the overall map. But the resulting links between the rooms don’t work as expected and you end up going round in circles!

I’ve also tried pre-defined rooms (similar to Aaron Reed in Dynamic Rooms) and those rooms are all linked into the map as I expect.

Is there something I have to do after cloning a room object? Is the room a fully-functional room after cloning? Maybe something specific only for cloned room objects is also needed?

At the moment I really do suspect there is a tricky bug somewhere in the Dynamic Objects extension and specifically the cloning of rooms isn’t as clean as it should be. I don’t think the clones are really independent objects, something tells me they are still internally linked to the original room object and then after cloning maybe to each other?

Here is a relatively small ‘hard-coded’ example of correct and incorrect behaviour with changing links to some pre-defined room objects and then with clones. Just compare going south three times and then returning north to the first room with trying to go north from the first room three times…

Can anyone see anything worng with the cloned rooms and linking of the exits? At the moment I’m stumped!

[spoiler]Include Dynamic Objects by Jesse Mcgrew.

Use slow route-finding.
[Slow route-finding should always be used with Dynamic Objects and cloned rooms]

The first room is a room.
[A room to act as a starting point for building]

The clone room is a room.
[A room to be cloned during building]

The second room, the third room and the fourth room are rooms.
[Three normal, initially un-linked empty rooms to be used during building]

When play begins:
[First place a set of 3 pre-defined rooms running south from the first room. These are not clones, they are simply linked into the correct positions by changing their exits. The resulting chain of rooms works as expected, after building you can go south 3 times and return north through the rooms to the first room.]
change the south exit of the first room to the second room;
change the north exit of the second room to the first room;
change the south exit of the second room to the third room;
change the north exit of the third room to the second room;
change the south exit of the third room to the fourth room;
change the north exit of the fourth room to the third room;
[Now place a set of 3 rooms all cloned from the clone room, running north. You can go north once, but then north again goes straight to the fourth clone room and then going north always goes to the fourth room. Going south goes to the third room and repeat south also goes to the third room!?! You cannot get back to the second clone room or the first room. For some reason the second, third and fourth clones seem to be linked incorrectly, why???]
let the second clone room be a new object cloned from the clone room;
now the printed name of the second clone room is “second clone room”;
change the north exit of the first room to the second clone room;
change the south exit of the second clone room to the first room;
let the third clone room be a new object cloned from the clone room;
now the printed name of the third clone room is “third clone room”;
change the north exit of the second clone room to the third clone room;
change the south exit of the third clone room to the second clone room;
let the fourth clone room be a new object cloned from the clone room;
now the printed name of the fourth clone room is “fourth clone room”;
change the north exit of the third clone room to the fourth clone room;
change the south exit of the fourth clone room to the third clone room.[/spoiler]

Map connections aren’t tracked by individual rooms, but by a fixed-size global array, called Map_Storage at the I6 level. It looks like this:Array Map_Storage --> 0 0 0 0 0 0 0 0 0 0 0 0 ! Exits from: I88_first_room 0 0 0 0 0 0 0 0 0 0 0 0 ! Exits from: I89_clone_room 0 0 0 0 0 0 0 0 0 0 0 0 ! Exits from: I90_second_room 0 0 0 0 0 0 0 0 0 0 0 0 ! Exits from: I91_third_room 0 0 0 0 0 0 0 0 0 0 0 0 ! Exits from: I92_fourth_room ;Each room knows what ‘row’ its exits are in (the IK1_count property at the I6 level), and this index is copied by dynamic objects when you clone something. So cloned rooms share exits. (Still, this is surely better than trying to use out-of-bounds rows.)

OK, it’s not a bug in Dynamic Objects (sorry for the assumption), it’s a feature. Unfortunately the result seems to be that re-linking cloned rooms may lead to other issues with exits from existing rooms.

Does dynamic cloning of rooms make any sense? Is there any practical use for cloned rooms?

I’ll go back to the ‘pool of rooms’ approach à la Dynamic Rooms and link them in and out of the map as required. But I don’t know if you have to be very careful with the inital size of the off-stage pool for rooms and objects (for the z-machine).

How much room does an empty room consume, if an empty room consumes room?! :unamused:

The memory usage of a room (or thing, or other object) depends on how many properties you stick on the kind and its members. For an estimate you can look in the index: “Contents” tab, “story file format”, click on the little “See estimates of memory usage” + button.