Possible to wait for a specific keypress to continue?

Hi.
I'm making pretty liberal use of the Wait function that pauses the game until a keystroke is registered, and I'm wondering if there is a way to restrict this so that only certain keys count as continuing. Right now, pressing pretty much any function key seems to continue the game, which prevents stuff like alt-tabbing in the middle of a scene. I've tried poking around in whatever files I can think of, but I don't really know where to start on this one.

Any suggestions would be greatly appreciated.


Not sure if this will help, and not sure as I haven't tested it.
Just looked up 'wait' command which has the regular expression
^wait$|^z$
And also 'WaitForKeyPress' function.
Not sure if you can change z$ to be a certain key, or put a character into the string box for the function.
Hope this helps. Although, you've probably looked at these two already.


That's about as far as I got. I'm only now getting to the point of using javascript, so although I found both the command and the function, I can't figure out if there is any way to edit them for my needs. Thanks for you input, though!


K.V.

Grep found the following (I don't know JS, so I don't know if this helps):

function beginWait() {
    _waitMode = true;
    $("#txtCommand").hide();
    $("#endWaitLink").show();
    markScrollPosition();
}

function endWait() {
    if (!_waitMode) return;
    sendEndWait();
}

function waitEnded() {
    _waitMode = false;
    $("#endWaitLink").hide();
    $("#txtCommand").show();
}

I tried this:

request (Wait, "")

Error running script: The 'Wait' request is not supported for games written for Quest 5.4 or later. Use the 'wait' script command instead.


More things grep found when I searched for 'wait' and/or 'keypress':

$(function () {
    $("#txtCommand").bind("inview", function (event, visible) {
        // allows spacebar to scroll browser when txtCommand is not visible
        if (visible == true) {
            $("#txtCommand").focus();
        } else {
            $("#txtCommand").blur();
        }
    });

    $("body").keydown(function (e) {
        if (_waitMode) {
            endWait();
        }
    });

var _waitMode = false;
var _pauseMode = false;

function beginPause(ms) {
    _pauseMode = true;
    $("#txtCommandDiv").hide();
    window.setTimeout(function () {
        endPause()
    }, ms);
}

function endPause() {
    _pauseMode = false;
    $("#txtCommandDiv").show();
    window.setTimeout(function () {
        $("#fldUIMsg").val("endpause");
        $("#cmdSubmit").click();
    }, 100);
}

function commandKey(e) {
    if (_waitMode) return false;
    switch (keyPressCode(e)) {
        case 13:
            runCommand();
            return false;
        case 38:
            thisCommand--;
            if (thisCommand == 0) thisCommand = numCommands;
            $("#txtCommand").val(commandsList[thisCommand]);
            e.preventDefault();
            break;
        case 40:
            thisCommand++;
            if (thisCommand > numCommands) thisCommand = 1;
            $("#txtCommand").val(commandsList[thisCommand]);
            e.preventDefault();
            break;
        case 27:
            thisCommand = numCommands + 1;
            $("#txtCommand").val("");
            e.preventDefault();
            break;
    }
}


you can use Commands, but you'll have to type it ('p' or 'pause') into the input command box:

(you can also create an Object with a 'pause' Verb/Script_Attribute, too)

<game name="example_game">
  <attr name="pause_boolean_attribute" type="boolean">false</attr>
</game>

<command name="pause_command">
  <pattern>pause;p</pattern>
  <script>
    if (game.pause_boolean_attribute) {
        game.pause_boolean_attribute = false
        msg ("Game: unpaused")
    } else {
      game.pause_boolean_attribute = true
      msg ("Game: paused")
    }
  }
</command>

you can use the 'get input' Function too:

<game name="example_game">
  <attr name="pause_boolean_attribute" type="boolean">false</attr>
</game>

<function name="pause_function">
  msg ("Press 'p' for pause/unpause")
  get input {
    if (LCase (result) = "p") (
      if (game.pause_boolean_attribute) {
        game.pause_boolean_attribute = false
        msg ("Game: UNpaused")
      } else {
        game.pause_boolean_attribute = true
        msg ("Game: paused")
      }
    } else if (game.pause_boolean_attribute) {
      msg ("Press 'p' to unpause the game")
    }
  }
</function>

The wait command is for when the player types "wait", and "z" is a standard shortform.

The wait script command is something entirely different and is what you use to wait for the player to press a key. It is hard coded so you cannot override it like most functions.

It may be possible to do this in JavaScript but would not be easy...


hegemonkhan, I realize now that my OP was a little unclear, but I was referring to the "Wait for keypress, then" function that forces the player to click continue or press a key to progress.

The Pixie, thanks for your reply. I'll have to make do with the standard behavior.


Does the keypress get assigned to anything? Could you do something like (pseudocode ahead)

Loop until (result = desired key)
{
wait
result = thing person pressed for wait
}

So you can't override the behavior of wait ending on any keypress, but you can make it so that the game issues a new wait command on any keypress except the one you like (which will look the same to the user)

I got around the problem by using showmenu to offer a one item menu marked "continue" so the player clicks on that to get things going again, but there are times that it is inelegant - I think a wait loop system might be better.


Check out the UFO game...
I believe it uses single key presses and responds to the individual key presses...

Actually... It as called "Space Invaders"
http://textadventures.co.uk/forum/games/topic/1xcgxubq2kqy_ckx7hm9jq/space-invaders-v0-03-now-real-time


K.V.

Following DL's link (indirectly) led me to an old post of HK's , which led to an old link of Pixie's, which led to an old link of Jay's:


Check this out:

https://textadventures.co.uk/forum/samples/topic/3546/map-generation-demo#28316

HookKeyboard.js

function HookKeyboard(callback) {
    var elem = document.getElementById('gameContent');
    elem.handleEvent = function (e) {
        ASLEvent(callback, e.keyCode.toString());
    };
    window.addEventListener("keydown", elem);
}
<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="HookKeyTest">
    <gameid>38ab633c-12fa-48bb-ac22-bcaf185c1b89</gameid>
    <version>1.0</version>
    <firstpublished>2013</firstpublished>
    <start type="script">
      JS.HookKeyboard("OnKeyDown")
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="OnKeyDown" parameters="keyvalue">
    msg ("Got key " + keyvalue)
  </function>
  <javascript src="hookkeyboard.js" />
</asl>

Then, a revision to the game (now the arrows move the player around):

https://textadventures.co.uk/forum/samples/topic/3546/map-generation-demo#28333

<!--Saved by Quest 5.5.5173.27901-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="HookKeyTest">
    <gameid>38ab633c-12fa-48bb-ac22-bcaf185c1b89</gameid>
    <version>1.0</version>
    <firstpublished>2013</firstpublished>
    <start type="script">
      JS.HookKeyboard ("OnKeyDown")
    </start>
  </game>
  <object name="cafeteria">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="north" to="garden">
      <inherit name="northdirection" />
    </exit>
    <exit alias="south" to="foyer">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="garden">
    <inherit name="editor_room" />
    <exit alias="south" to="cafeteria">
      <inherit name="southdirection" />
    </exit>
    <exit alias="north" to="path">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="path">
    <inherit name="editor_room" />
    <exit alias="south" to="garden">
      <inherit name="southdirection" />
    </exit>
    <exit alias="north" to="outlook">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="outlook">
    <inherit name="editor_room" />
    <exit alias="south" to="path">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="foyer">
    <inherit name="editor_room" />
    <exit alias="north" to="cafeteria">
      <inherit name="northdirection" />
    </exit>
    <exit alias="west" to="west landing">
      <inherit name="westdirection" />
    </exit>
    <exit alias="east" to="east landing">
      <inherit name="eastdirection" />
    </exit>
  </object>
  <object name="west landing">
    <inherit name="editor_room" />
    <exit alias="east" to="foyer">
      <inherit name="eastdirection" />
    </exit>
    <exit alias="west" to="west hallway">
      <inherit name="westdirection" />
    </exit>
  </object>
  <object name="east landing">
    <inherit name="editor_room" />
    <exit alias="west" to="foyer">
      <inherit name="westdirection" />
    </exit>
    <exit alias="east" to="east hallway">
      <inherit name="eastdirection" />
    </exit>
  </object>
  <object name="west hallway">
    <inherit name="editor_room" />
    <exit alias="east" to="west landing">
      <inherit name="eastdirection" />
    </exit>
  </object>
  <object name="east hallway">
    <inherit name="editor_room" />
    <exit alias="west" to="east landing">
      <inherit name="westdirection" />
    </exit>
  </object>
  <function name="OnKeyDown" parameters="keyvalue">
    //msg ("Got key " + keyvalue)
    switch (keyvalue) {
    	case (37) {
    		// left
    		JS.sendCommand("west", null)
    	}
    	case (38) {
    		// up
    		JS.sendCommand("north", null)
    	}
    	case (39) {
    		// right
    		JS.sendCommand("east", null)
    	}
    	case (40) {
    		// down
    		JS.sendCommand("south", null)
    	}
    }
  </function>
  <javascript src="hookkeyboard.js" />
</asl>

ALSO:

http://textadventures.co.uk/forum/quest/topic/3847/how-can-i-impliment-an-image-based-health#25765

I had done a test a while back about trapping keydown events in JavaScript. I've shown myself it can be done, and the attached sample shows one way to do it.

You need to include the JS file "glue.js" in your project. Then you simply call:

JS.Hook("somefunctionname")

and then that function whose name you pass will be called whenever a key is pressed - any key (even shift, ctrl, caps lock).

<function name="somefunctionname" parameters="keyCode">
    msg("Keycode = " + keyCode)
</function>

Note that this is using ASLEvent to notify the app. And ASLEvent (I recently discovered) causes turn scripts to run. Bear that in mind.

BTW, feel free to change the names. This was just some test code, so you have names like "Hook" and "glue". :)

KeyTest.zip


glue.js

function Hook(callback) {
    var elem = document.getElementById('gameContent');
    elem.handleEvent = function (e) {
        console.log("code = " + e.keyCode);
        ASLEvent(callback, e.keyCode.toString());
    };
    window.addEventListener("keydown", elem);
}

Here are the key's 'keys':

HookKeyTest

You are in a room.
Got key 65
Got key 66
Got key 67
Got key 68
Got key 69
Got key 70
Got key 71
Got key 72
Got key 73
Got key 74
Got key 75
Got key 76
Got key 77
Got key 78
Got key 79
Got key 80
Got key 81
Got key 82
Got key 83
Got key 84
Got key 85
Got key 86
Got key 87
Got key 88
Got key 89
Got key 90

abcdefghijklmnopqrstuvwxyz


forgot all about Jay's hook' coding and thus forgot to link to Jay's code, but K.V. found it, hehe.

the 'event listener' is found within 'Java' programming, so if you want and can, study up on 'Java' programming, as it has a lot of these event listeners and etc input controls, as Java is good for creating GUI type of stuff. Probably quest has similar coding to how its done in Java's programming.

Again, 'Java' is a full-bore language, which is completely different than the 'JS (JavaScript)' scripting language.

https://docs.oracle.com/javase/tutorial/

and for the Values of keyboard keys:

http://www.asciitable.com


K.V.

I've been playing with the Hook function, and I can make it do something after a keypress, but I can't make it NOT do the default action for a key press.

I.e., I can't stop the up arrow from scrolling through commands.

I can make it print a message (or do whatever else I want) when you press the up arrow, but it scrolls through the commands no matter what.

Same with letters.

If you hit B, I can make something happen right then, but 'B' still goes into the input field.


This code, which is a combination of HK's script and one of XanMag's scripts won't let you do jack until you enter 'g' (but you have to press ENTER, it's not a hook... although it could be):

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="you must press 'g'">
    <gameid>7f31eee7-ee5a-4ea5-841b-afc6a8ca0698</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <start type="script">
      loopit
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="loopit"><![CDATA[
    msg ("CLUE: the 7th letter<br/>")
    PrintCentered ("<b><u>PLEASE ENTER THE ANSWER NOW{notfirst:<br/><br/> (You must enter the correct response to proceed!)}</u></b><br/>")
    get input {
      switch (LCase(result)) {
        case ("g") {
          firsttime {
            msg ("\"" + result + "\" is correct!<br><br>Good job!")
          }
          otherwise {
            msg ("\"" + result + "\" is incorrect.<br>")
            msg ("Try again.<br/>")
            loopit
          }
        }
        default {
          msg ("\"" + result + "\" is incorrect.<br>")
          msg ("Try again.<br/>")
          loopit
        }
      }
    }
  ]]></function>
</asl>

you must press 'g'

CLUE: the 7th letter

PLEASE ENTER THE ANSWER NOW

"a" is incorrect.

Try again.

CLUE: the 7th letter

PLEASE ENTER THE ANSWER NOW

(You must enter the correct response to proceed!)

"g" is correct!

Good job!
You are in a room.


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

Support

Forums