Hi,
It's been a while since I used Quest and I've just realised I have been using the wrong forum for my QuestJS questions! I was pleased to see that this has been developed, and the Git wiki is excellent, but is there any kind of support here still? I appreciate everyone's busy but I have some pretty basic questions - like creating an if/else within a conversation based on if the player is holding an item.
askOptions:[
{
test:function(p) { return p.text.match(/door/); },
if (w.key.isHeld()) {
msg("'You have my key', he says.")
return false
}
else {
msg("He says you don't have the key")
return true
}
I've also tried
if (w.marlinspike.loc === 'me'()) {
I don't know if I'm on the right lines and have just placed this incorrectly, or if I'm way off. Maybe I need to nest a second function?
A bit late on a response, I hope this is still relevant. Your logic is sound, there's just a little syntax issue with the way you're creating the item. Each attribute inside an object needs to be a key-value pair, where the key is usually a string and the value could be anything (including another object or array, or even a function).
In this example, askOptions is an array of objects. The first and only object has two key-value pairs, a key called test with a value of the conditional statement (if the text matches), and a key called script, with a value of the function to run when the test script returns true.
createItem("doorman", NPC(false),
{
loc:"lounge",
examine:"A man at the door.",
askOptions:[
{
test:function(p) { return p.text.match(/door/); },
script:function() {
if (w.key.isHeld()) {
msg("'You have my key', he says.")
}
else {
msg("He says you don't have the key")
}
},
},
],
});
createItem("key", TAKEABLE(), {
loc:"lounge",
examine:"A key."
});