Make a Quest game respond to ENTER press with no input

In the old text adventures I played, the game responded when you pressed ENTER with nothing to parse.

This code in your game.inituserinterface script will make Quest do that.

This will make it say "I beg your pardon?"

JS.eval ("function runCommand() {var command = $('#txtCommand').val();if (command.length > 0 && canSendCommand) {numCommands++;commandsList[numCommands] = command;thisCommand = numCommands + 1;sendCommand(command);$('#txtCommand').val('');} else if (command.length === 0 && canSendCommand){addTextAndScroll('<br/>><br/>I beg your pardon?<br/>')}}")


The original:


That's an interesting way to do it :)

I would probably have changed the function runCommand to skip the check for there being something in the input box. So…

JS.eval("runCommand=function(){var a=$('#txtCommand').val();canSendCommand&&(numCommands++,commandsList[numCommands]=a,thisCommand=numCommands+1,sendCommand(a),$('#txtCommand').val(''))};")

Then you can make a command with a regex pattern ^$ to match an empty line. Means that if you want to, you could have parts of the game where it gives a different response (like an NPC who responds to you saying nothing).

Hey, that's a better idea!

I didn't even see that part of the code.

I've talked about the differences between Quest and Basic...
That's a LOT of code just to do what Basic can do without breaking a drop of sweat...
In Basic, the GetInput command is just input.
With variations:
Input "What is your name?", Name
Name would be the same as result... but that aside...
A simple check:
if Name="" then print "What was that?"
if len(Name)<1 then print "Sorry, were you mumbling?"
Is there a way to check:
if lengthOf(result)<1 {
msg ("I'm sorry, I didn't get that. Please try again.")

Well, that didn't work so easy, maybe there could be a change in the core code?

What's len? I see that in ZIL when dealing with the input, too.

Len= LengthOf
Hmmm, maybe knowing a little Basic could help.

Oh, I would have seen that if I'd kept reading that code past that line.

That len isn't the same as the one in ZIL.



I was mistaken, anyway. It's LEX in the ZIL code; not len.

That's a LOT of code just to do what Basic can do without breaking a drop of sweat...

In fairness, that is because Quest - and I would guess pretty much all IF systems (except QuestJS) - deliberately insulate authors from the low level input system.

Maybe to prevent problems when the user hits the enter more than once.
BUT, it would be nice to be able to access some of that "insulated" stuff.

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