Quest 6: Function For Creating Exits

1234676543224
23 Nov 2022, 22:40

Hello,
Sorry in advance if this is in the wrong forum.
I am wondering if there is a function in Quest 6 similar to the create exit() function in Quest 5.


The Pixie
25 Nov 2022, 18:14

No there is not. The reason is how games are saved. Any exit that is created during play will not be saved.

There will be ways to work around that. What are you trying to do?


1234676543224
26 Nov 2022, 03:38

I am attempting to create a sort of open-world game with infinite amounts of rooms that are cloned.


The Pixie
27 Nov 2022, 15:33

The way to do this would be not using exits at all. QuestJs does it all through the room, so for example it will use the room's "getExit" to get the exit attribute. You can give your rooms their own "getExit", that instead returns an exit on the fly.

I will have a think about this, and say more later, probably in the docs, but it may be a week or so.


The Pixie
27 Nov 2022, 16:04

As a first stab, something like this - but I have not tried it at all, so likely to need some tweaking!:

createRoom('room_prototype', {
  getExit:function(dir) {
    if (this['exit_' + dir] === undefined) return undefined
    return new Exit(this['exit_' + dir], {origin:this, dir:dir})
  },
  
  hasExit:function(dir, options) {
    if (options === undefined) options = {}
    if (!this['exit_' + dir]) return false
    if (options.excludeLocked && this.isExitLocked(dir)) return false
    return !this.isExitHidden(dir)
  },
  
  findExit:function(dest, options) {
    if (typeof dest === "object") dest = dest.name;
    for (let exit of lang.exit_list) {
      if (this.hasExit(exit.name, options) && this['exit_' + dir] === dest) {
        return this[exit.name];
      }
    }
    return null;
  },
}

The Pixie
30 Nov 2022, 12:49

Updated. See the docs here:
https://github.com/ThePix/QuestJS/wiki/Creating-objects-on-the-fly#cloning-rooms

You will need the most recent version of _templates, _defaults and _world from Github.


1234676543224
02 Dec 2022, 16:54

Thank you!