Navigating choices with arrow keys and text input?

Hello there!
I'm new to creating text games and I am stuck on implementation:
I want to have a list of options on the 'welcome screen' which users can navigate using text or arrow keys (then hitting the enter button to choose option)
I know clicking is an option, but in this case it would ruin the aesthetic I'm going for.

Thanks in advance!
Joe


If you use ShowMenu to present a list of options, the user can enter the number of the choice they want.

I've previously posted some function overrides which allow the player to type the start of one of the menu options instead.

Using arrow keys should be possible using javascript, if you're sure this is how you want it to work.


Do you mean like:
Scroll up and down with the arrow keys to select want you want?
Check out the "setting" for my Wumpus game...
http://textadventures.co.uk/games/view/g4jaujz2ceipk6vi3cfx0a/wumpus-3-0
Each "control" changes with each selection... Not arrow keys, but...
And yes, it is a WIP that I haven't gotten back to...


Thank you all for your lightning fast responses!
mrrangel, I'm currently using ShowMenu to present the list, I would just really love the idea of the user being able to scroll through options with arrow keys as well. I might just have to learn javascript... haha.
DarkLizerd, I'm not sure exactly what element you're talking about in your game- anything more specific?

For example, on my very first screen , it reads:

Welcome, USER!

What would you like to access?

-MESSAGES
SEARCH
DEVICES
QUIT


From here, the player could type "access" or "open" MESSAGES (which is its own screen) but I was hoping for arrow navigation as well. That way, players could switch if their fingers are getting too tired or they are panicking( game will eventually hopefully be tense/scary)
If anyone here happened to create something similar to this that they would be willing to share, I would be most appreciative, or if not- maybe just a nod in the right javascript direction. I designed this game to be very small and simple (with only 4 or 5 main screens) so after I figure this out the rest should be relatively easy haha.

Thanks again!


Like this???

Menu:
*Messages
-Search
-Devices
-Quit

(Hit down arrow)
Menu:
-Messages
*Search
-Devices
-Quit

(Hit down arrow)
Menu:
-Messages
-Search
*Devices
-Quit

(Hit up arrow)
Menu:
-Messages
*Search
-Devices
-Quit

(Hit Enter to select "Search")


Yes, exactly like that!


There is a demo code for arrow input, Key test, that uses single key press events.
BUT, it uses JS code, and is pre-programed for directions... North, East, South, and West...
I'm trying to work it out what to change to work with a menu...
But I'm sure someone here can get it to work faster than me...


It should be fairly simple, but you'd likely need to adjust ShowMenu so that your script knows which links are part of the menu.

Actually, jQuery span:has(a[onclick^='ASLEvent(\'ShowMenuResponse\'']) might find a list of menu options; but feels a little ugly.
Once you have a list of the options, you could add a 'selected-menu-item' class to the one that's currently selected, which maybe highlights it in bold or something similar. Pressing up or down would find the currently selected item, remove that class, and add the class to the next or previous link.
It could also focus the appropriate link (so that pressing enter clicks the link without needing any additional code), or finds the number of the option and puts it into the command bar.


In BASIC, I could do this in a heartbeat... But Quest is "not quite BASIC"...


I doubt input would work with arrow keys...

But something like this would work.

msg ("Pick a number.")
get input {
  if (result = 1) {
  }
  if (result = 2) {
  }
  msg ("Thanks!")
}

How do you disable input you don't want anyway? I keep messing around with naming characters, and I keep getting "Nice to meet you, Take Hat!"


How do you disable input you don't want anyway? I keep messing around with naming characters, and I keep getting "Nice to meet you, Take Hat!"

That made me smile. But to fix the issue…

msg ("What is your name?")
game.unresolvedcommandhandler => {
  player.alias = command
  msg ("Pleased to meet you, {player.alias}!")
  game.unresolvedcommandhandler = null
  destroy ("entername_timeout")
}
SetTurnTimeoutID (2, "entername_timeout") {
  msg ("Don't want to tell me your name? Fine! See if I care!")
  player.alias = "Anon" + GetRandomInt(1001,9999)
  game.unresolvedcommandhandler = null
}

If the question is mandatory, have a function which asks the question. When you get your result, do something like:

is_command = false
foreach (cmd, ScopeCommands()) {
  if (IsRegexMatch (cmd.pattern, result)) {
    is_command = true
  }
}
if (is_command) {
  msg ("I asked for your name, not a command, idiot.")
  // call the function again to repeat the question
}
else {
  player.alias = result
}

@mrangel

The first one works.

The second one gives me this error.

Error running script: Error compiling expression 'IsRegexMatch (cmd.pattern, result)': Unknown object or variable 'result'

How do I make it so that the room description stuff plays afterwards? Actually, the room description is a script, and the description is made up of messages.

fname
msg ("Hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii!!!<br/>....<br/>Righto.<br/><br/>Now, the Pokémon... They are... magical creatures. Sometimes they are animals, and sometimes they are objects (such as Pokéballs) that come to life.<br/><br/><br/>You are.... um... in your room.<br/>Commands you should know; Heal Oran Berry me, Heal Sitrus Berry me, Rest me, Access object, Egress object, Look at object, x object, Check object, Scan object<br/><br/>Equip Pokemon.<br/>Save often. I recommend saving every 30 minutes.<br/><br/>Do you need any other help?")
a show menu
msg ("Testing. 1. 2. 3.")

The second one gives me this error.

You haven't asked a question.
That isn't a complete script. It needs to be inside the get input block. It just discards all inputs that are valid commands.


Log in to post a reply.

Support

Forums