A HINT Command ‐ Dynamic Hints - ThePix/QuestJS GitHub Wiki
If your game has puzzles of any sort, there is a chance the user will get stuck and might appreciate a hint. How might you create a HINT command?
Dynamic hints change as the player progresses through the game. For example, the player is stood before a locked door, and the user types HINT. The system realises where the user is stuck, and responds "Maybe the ogre has a key".
We can use the respond function to handle this, and in fact the HINT commad is already set up to do this. All we have to do is let up a list of responses called settings.hintResponses
. That said, creating the list is not trivial, as it has to cover a lot of diverse situations, so be aware of that before you commit to this!
Here is a very simple example; the player has to pick up a key, and can then go west. Each entry in the list (except the last) consists of a "test" and a "msg". The "test" has to be a function, and the function must return true if the hint is now applicable. The "msg" is just the text to print.
The last entry is a general catch-all, so has no test.
settings.hintResponses = [
{
test:function() { return currentLocation.name === 'practice_room' && w.small_key.loc !== player.name; },
msg:"Get the key.",
},
{
test:function() { return currentLocation.name === 'practice_room' },
msg:"Now you have the key, the door to the west should unlock.",
},
{
msg:"Sorry, no hints currently available.",
failed:true,
}
],
We can refine that somewhat. Firstly, we can nest the entries. All that relate to opening the door can be lumped together. Instead of testing where the player is, we test whether the door is locked, and that will be used for all the entries nested inside of that, as "responses".
Also, the key is now hidden in the study as scenery originally, and the hint system can check that too, so now we have three hints. Not that Quest starts at the top and continues until it finds a test that works.
settings.hintResponses = [
{
test:function(p) { return w.practice_room_door.locked },
responses:[
{
test:function(p) { return w.small_key.scenery },
msg:"Maybe there is a key in study?",
},
{
test:function(p) { return w.small_key.loc !== player.name },
msg:"Get the key.",
},
{
msg:"Now you have the key, the door to the west should unlock.",
},
],
},
{
msg:"Sorry, no hints currently available.",
failed:true,
}
],
You might also want to consider an in-game hint system. Perhaps an oracle the player can consult or a sarcastic companion... The default uses metamsg
to print hints, but you can set it to use the usual msg
by setting settings.hintResponsesInGame
.
You can also include "script" attributes if you want the companion to change state (or for any of these dynamic systems). In the example below, the situation with the key being scenery has been further nested, and has three responses, depending on how many times the player has asked, with the "script" attribute being used to increment the "keyHintCount" attribute on the NPC. This could also be used to give progressively more explicit clues.
Note that JavaScript will treat undefined
and zero as being false, so the first test will return true if the "keyHintCount" attribute is 0 or is not set.
settings.hintResponsesInGame = true
settings.hintResponses = [
{
test:function(p) { return w.practice_room_door.locked },
responses:[
{
test:function(p) { return !w.Lara.keyHintCount },
responses:[
{
test:function(p) { return !w.Lara.keyHintCount },
msg:"'Maybe there is a key in the study?' says Lara.",
script:function() { w.Lara.keyHintCount = 1 }
},
{
test:function(p) { return w.Lara.keyHintCount == 1},
msg:"'I still think we should look for a key in the study,' says Lara.",
script:function() { w.Lara.keyHintCount = 2 }
},
{
test:function(p) { return w.small_key.scenery },
msg:"'Just look in the damn study for the key, alright?' says Lara. She sighs heavily.",
},
],
},
{
test:function(p) { return w.small_key.loc !== player.name },
msg:"'Get the key,' says Lara. 'The one we found in the study.'",
},
{
msg:"'Well, you got the key, can we please go through the stupid door now?'",
},
],
},
{
msg:"Sorry, no hints currently available.",
failed:true,
}
]