Cloning a room - contents?

Before I do a load of experiments to work out what to do in this situation, maybe somebody can tell me. People have done random dungeon creators before, so somebody probably knows:

If I clone a room, what happens to its contents?

  • Are items in the room also cloned?
  • Are exits from the room duplicated?
  • Are exits to the room duplicated?
  • Are the _initialise_ or changedparent scripts called for objects duplicated in this way?

And the biggest question:

  • Is there a good way to make this easier, without falling foul of any weird gotchas, that someone who's been here before can suggest?

DarkLizerd imported the Wumpus, which uses a dungeon spawner script...


Not sure if this is what you are asking, but I've copied and pasted rooms and it duplicates everything about the room. Exits, objects, scripts... even the player! Hope that helps.


OK... I spent a while running test cases.

Conclusions:

  • Cloning a room does clone all its contents
  • Objects inside a cloned room get a changedparent event
    • They think they've been moved from the original room to the clone
    • There's no easy way for the changedparent script to distinguish between a move and a clone

As I have all my exits with a 'reverse' attribute that points to the exit in the other direction, and a changedparent that changes the other side's to to keep them in sync (and vice versa), this would result in both the original and cloned exits being in the clone room, and the exit 'to' the original room being moved to the clone.

As far as I can see, the simplest way to deal with this would be something like:

movedobjects = NewObjectList()
foreach (o, ListCombine (GetDirectChildren(this), ScopeExitsForRoom(this))) {
  if (not GetBoolean(o, "plenty") or RandomChange(50)) {
    list add (movedobjects, o)
    if (o = game.pov) {
      o.silentmovement = true
    }
    o.parent = null
  }
}
newroom = CloneObject (this)
dir = RandomDirection()
MakeExits (this, newroom, dir)
foreach (o, movedobjects) {
  if (o.alias = dir) {
    o.parent = newroom
  }
  else if (o.alias = ReverseDirection(dir)) {
    o.parent = this
  }
  else if (Randomhance(50)) {
    o.parent = this
  }
  else {
    o.parent = newroom
  }
  if (o = game.pov) {
    o.silentmovement = false
  }
}

Is there anything unexpected that's likely to jump up and bite me with that?


Amochure  Oct 4, 2017 10:39 AM new
Not sure if this is what you are asking, but I've copied and pasted rooms and it duplicates everything about the room. Exits, objects, scripts... even the player! Hope that helps.

Wait, the player? Does it clone the player too, or just the player object???


this is a good question...

'deep copying' vs 'shallow copying'

http://www.cs.utexas.edu/~scottm/cs307/handouts/deepCopying.htm (no idea how good this link is - briefly looked at it only, just google search: deep vs shallow copying, if you want to look for better links)

// or (I am using an old apple computer and browser, so it can't handle the 'https / secure http' url usage, argh), so here's the normal/secure (shttp) link of it for everyone with a modern computer/browser, lol:
https://www.cs.utexas.edu/~scottm/cs307/handouts/deepCopying.htm

does quest automatically do 'deep copying' without you having to manually do it (you just do 'shallow copying', but underneath quest actually does 'deep copying') or do you have to manually do 'deep vs shallow' copying ???


HK: I know what a deep copy is. That's not what I asked.

I think that making a trivial test game to check something is when I hate the web editor most; because just creating an object that needs no detail beyond a name takes 5-10 seconds longer than it should. Building a simple test game (two rooms, a pair of exits, and a command that clones one of them) took me half an hour. So, sorry to keep asking things I should be able to check myself.


I think hegemonkhan was trying to say my question with different wording.

"Building a simple test game (two rooms, a pair of exits, and a command that clones one of them) took me half an hour."

You must have done something else because holy crap, that's not very much for one hour!

I know that typing the name for an object takes awhile, but it needs a name. Just like any other program or folder, or Word Document, or something. When I am lazy, I just type random letters anyway. uhfu


I meant that this topic is similar to how quest handles (at least the concept anyways) of 'deep vs shallow copying', as I'm still a bit of a noob in understanding these coding concepts and with how quest works.


@ mrangel:

I wasn't responding to your post directly (and I know you know what 'deep/shallow copying' is, as you're a good/knowledgeable programmer, I'm still taking lower division classes / am a noob programmer), sorry if it came off like that.


@ jmnevil54:

I wasn't responding directly to your post too, lol.


I was just making a comment, that to me, the topic of how quest deals with nested Objects/Attributes when copying, seems to be similar to the concept of 'deep vs shallow copying', and hoping that I could get repsonses on it, explaining it to me (whether I am on the right track or not, lol), as I still have some trouble with these code concepts and that I don't know how quest works much.


P.S.

@ mrangel:

I totally understand that too (we're of the same mind, lol), except for me, it's just due to me being uber lazy, lol.

I'm lazy, so I just ask a question here, hoping to get a quick answer/response, instead of testing it myself and getting an answer.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums