How do we handle enterable objects (or non-directional exits)? #131
-
|
Porting a Quest 5 game (actually a Quest 2 game, but this works the same in Quest 5, and I'm porting a v5 port of a v2 game)... I have a room called I cannot (for the life of me) figure out how to handle this. I find this: wiki/Attributes-for-items#goindirection-gooutdirection-goupdirection-godowndirection-gothroughdirection
This makes me think there is no way to do this without actually assigning a directional exit for each room? Both exits would technically be "in" from Zeke's Farm. The "in" exit could be a script that asked "Do you want to go into the farmhouse or the silo?" ...but I can't figure out how to pull that off, either, hehehe. Really, I think both exits should simply allow GO TO, and that's all. I guess I could create a SE for the farmhouse and a SW for the silo, and hide both of those exits, but I'd rather not. I feel like I'm just overlooking something... ...and I can't find the function to modify the behavior of the ENTER command to just let me move the player. If I don't add something like "use strict"
createItem("player", PLAYER(), {
examine:function() {
msg ("You look like you're ready for an adventure. ")
},
loc:"kowwsChasm",
})
createRoom("kowwsChasm", {
alias: "Koww's Chasm",
east: new Exit("zekesFarm"),
desc:"This room is under construction. You can go east."
})
createRoom("zekesFarm", {
usedefaultprefix:false,
alias:"Zeke's Farm",
desc:"Welcome to the farm! You can go west.",
west: new Exit("kowwsChasm")
})
createItem("zekesFarmhouseEntrance", {
loc:"zekesFarm",
alias:"Zeke's Farmhouse",
enter:function(){
player.moveChar("zekesFarmhouse")
return world.SUCCESS
},
verbFunction:function(list) {
list.push("Enter")
}
})
createItem("zekesSiloEntrance", {
loc:"zekesFarm",
alias:"Zeke's Silo",
enter:function(){
player.moveChar("zekesSilo")
return world.SUCCESS
},
verbFunction:function(list) {
list.push("Enter")
}
})
createRoom("zekesFarmhouse", {
alias:"Zeke's Farmhouse",
desc:"The farmhouse is under construction! You can go out.",
out:new Exit("zekesFarm")
})
createRoom("zekesSilo", {
alias:"Zeke's Silo",
desc:"The silo is under construction! You can go out.",
out:new Exit("zekesFarm")
})Somebody help! 🤣 PS I ported this game to ZIL (Zork Implementation Language), and I just made doors to handle this bit. It seems like we can use doors in QuestJS, too, but it looks like it would still require an actual direction set to one location. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
I think I got it. Everything seems to work. Added to code.js: commands.unshift(new Cmd('GoTo', {
npcCmd:true,
regex:/^(?:go to|go) (.+)$/,
objects:[
{scope:parser.isHere}
],
script:function(objects) {
const entrance = objects[0][0]
if (typeof entrance.otherSide == 'undefined') return failedmsg("{pv:item:be:true} not an entrance.", {item:entrance})
for (const ex of currentLocation.dests) {
log(ex.name)
if (entrance.otherSide === ex.name) {
return ex.use(player, ex) ? world.SUCCESS : world.FAILED
}
}
return failedmsg("{pv:item:be:true} not an entrance you can get to from here.", {item:entrance})
},
}))Added to settings.js: settings.setup = function() {
for (const key in w) {
const o = w[key]
if (o.dests) {
for (const ex of o.dests) {
const dest = w[ex.name]
if (!dest) log('Warning: ' + ex + ' in the destinations for ' + key + ' is not a location.')
ex.origin = o
ex.dir = 'to ' + (ex.dirAlias ? ex.dirAlias : dest.alias)
}
}
}
}"use strict"
createItem("player", PLAYER(), {
examine:function() {
msg ("You look like you're ready for an adventure. ")
},
loc:"kowwsChasm",
})
createRoom("kowwsChasm", {
alias: "Koww's Chasm",
east: new Exit("zekesFarm"),
desc:"This room is under construction. You can go east."
})
createRoom("zekesFarm", {
usedefaultprefix:false,
alias:"Zeke's Farm",
desc:"Welcome to the farm! You can go west.",
west: new Exit("kowwsChasm"),
dests:[
new Exit("zekesFarmhouse"),
new Exit("zekesSilo")
],
})
createItem("zekesFarmhouseEntrance", {
loc:"zekesFarm",
alias:"Zeke's Farmhouse",
otherSide:"zekesFarmhouse",
verbFunction:function(list) {
list.push("Go to")
},
})
createItem("zekesSiloEntrance", {
loc:"zekesFarm",
alias:"Zeke's Silo",
otherSide:"zekesSilo",
verbFunction:function(list) {
list.push("Go to")
},
})
createRoom("zekesFarmhouse", {
alias:"Zeke's Farmhouse",
desc:"The farmhouse is under construction!",
out:new Exit("zekesFarm")
})
createRoom("zekesSilo", {
alias:"Zeke's Silo",
desc:"The silo is under construction!",
out:new Exit("zekesFarm")
}) |
Beta Was this translation helpful? Give feedback.
-
|
That's a clever solution, I like the user experience of allowing the player to type
I did try to come up with a solution that went in this direction, taking inspiration from the section on To use it, just specify On one hand, it does seem nice to allow the player to consistently use |
Beta Was this translation helpful? Give feedback.
That's a clever solution, I like the user experience of allowing the player to type
go to farmhouseorgo to silo. Simple and easy to understand.I did try to come up with a solution that went in this direction, taking inspiration from the section on
simpleUse()on this page. Basically, we create a subclass of Exit that can be passed an array of rooms. Then when the player uses the exit, we ask which room they want to go to and "create a disposable exit on the fly" with the selected destination.