Is there a null result to 'get input'?

Forgewright
24 Apr 2020, 04:00get input {
if (result = null) {
HandleSingleCommand ("Back to the action!")
}
Ask ("Is this what you want to add to the journal?<br>" + result) {
if (result) {
list add (player.playeraddjournal, game.answer)
HandleSingleCommand ("journal")
msg ("<br><center>You have written in your journal.")
game.nojournal = True
}
else if (result = false) {
HandleSingleCommand ("journal")
}
}
}
I want the third line HandleSingleCommand ("Back to the action!")
to run if the player just presses the "ENTER" key.
There are instructions to do this before this script.
Does hitting the "enter" key pass a result other than the fact you pushed it?

Dcoder
24 Apr 2020, 04:23get input
gives a string result, not an object, so null
wouldn't apply. Just do for the first three lines:
get input {
if (result = "") {
msg ("Back to the action!")

Forgewright
24 Apr 2020, 05:55Pretty sure I did this already. Tested it again and nothing happens when I press enter. Took me 8 hours to write this code. 6 of it was trying to solve this.

Forgewright
24 Apr 2020, 05:57Whole script work but that one dang line
ViewObjectScreen
request (Show, "Command")
msg ("<center><h2>William's Journal")
msg ("<center><em>{color:silver:--------These are quests added by the game--------}")
if (ListCount(player.journal) = 0) {
msg ("<center>NO ENTRIES YET!")
}
msg ("<center>------------------------------------------")
foreach (s, player.journal) {
msg (s)
}
msg ("<br><br><center><em>{color:silver:--------These are notes are added by you--------}")
if (ListCount(player.playeraddjournal) = 0) {
msg ("<center>NO ENTRIES YET!")
}
msg ("<center>------------------------------------------")
foreach (n, player.playeraddjournal) {
msg (n)
msg ("")
}
msg ("<center><small><em><br>Please type in the box below to enter the information if you want to add to your journal notes. Then press ENTER.")
msg ("<center><small><em><br>Press 'ENTER' to close the journal")
get input {
game.answer = result
if (result = "") {
HandleSingleCommand ("Back to the action!")
}
Ask ("Is this what you want to add to the journal?<br>" + result) {
if (result) {
list add (player.playeraddjournal, game.answer)
HandleSingleCommand ("journal")
msg ("<br><center>You have written in your journal.")
game.nojournal = True
}
else if (result = false) {
HandleSingleCommand ("journal")
}
}
}
EDIT: Forgot to add this line after get input.
game.answer = result
I did have player type 'exit' and then had the line read:
if (result = "exit") {
and that works. just wanted it to be a keypress of 'enter'.

Dcoder
24 Apr 2020, 06:30Ok, I just tested out my code and you can't enter (nothing) as the input (although you can enter a blank space). So you would have to include a message like:
msg ("Enter X to cancel")
if (result = "x") {
msg ("Back to the game")
}
else {
msg ("Something else happens")
}
mrangel
24 Apr 2020, 09:47Haven't tried it, but I think putting JS.eval("$(function () {var a=runCommand;runCommand=function(){sendCommand($("#txtCommand").val());runCommand=a;};});")
immediately before a get input
should allow the player to input an empty string. (I've made it restore the original behaviour afterwards, because sending an empty string to the parser might cause errors)

Forgewright
24 Apr 2020, 14:05Tried your line of code Mrangel. Throws error of unexpected character, line 1, column 71. It is far beyond me And I would never figure it out.
mrangel
24 Apr 2020, 16:23Sorry, forgot to escape it.
If one of my JS.eval
lines gives that error, the most likely cause is that there's a "
or a \
in the middle of it somewhere. Either put a \
before the offending character, ot change "
to '
.
So that line should be either:
JS.eval("$(function () {var a=runCommand;runCommand=function(){sendCommand($(\"#txtCommand\").val());runCommand=a;};});")
or
JS.eval("$(function () {var a=runCommand;runCommand=function(){sendCommand($('#txtCommand').val());runCommand=a;};});")
(When the player presses enter, it triggers the runCommand
function, which looks at the text in the command bar, and if it's longer than 0 characters passes that to the function sendCommand
. I replaced it with a modified version:
JS.eval("
- pass the command to the javascript interpreter$(function () {
- A guard function. I use this every time I do javascript in Quest, because it prevents a ton of confusing errors that are very hard to debug.var a = runCommand;
- stores therunCommand
function in a local variablea
.runCommand = function () {
- creates a new runCommand function, which will:sendCommand (
- send a command to the Quest backend (without checking if it's an empty string)$('#txtCommand').val()
- current value of the input box with ID "txtCommand" (the command bar)
);
runCommand = a;
- change the runCommand function back to the default one we saved earlier
};
})
- end of the guard function
")

Forgewright
24 Apr 2020, 19:42Thanks for the rundown on the code. It line works great so far.