Talk:How do I customize the keyboard?
Mike: You know, it's funny. I distinctly recall asking you about such a command mid-2003, for a script that looked a lot like this.
Bob: yeah. that mail is probably still in my "suggestionbox" mailbox :) I thought we did this recently, but I was mistaken. Ah, well, it will go nicely with menu customization.
Raekuul: The main menu call thing sounds like a misreferenced thingummy... maybe if we could get someone to go through the code, line by line, action by action, gosub by gosub, then maybe we could find a good enough anchor to call the main menu... (and, no, this I cannot do... yet). The problem with calling the main menu would be that there's no way to prevent saving in such an instance (unless the option is completely removed...), in comparison to just calling the "save menu".
Mike: Why would you care? It would be identical to hitting escape. And, if you want to disable saving, you just turn saving off in the map.
TheCube: So I am messing with this (because I would REALLY like to use Z and X instead of the normal buttons), and so I threw this together from the script on the article:
plotscript, keypress handler, begin variable (x,y,d,) if (hero is walking(me) == false) then,begin if (topmenu == false) then,begin if (key is pressed(Key:Up)) then (walk hero(me, up, 1)) if (key is pressed(Key:Left)) then (walk hero(me, left, 1)) if (key is pressed(Key:Down)) then (walk hero(me, down, 1)) if (key is pressed(Key:Right)) then (walk hero(me, right, 1)) end if (key is pressed(Key:Z),or,key is pressed(Key:R)) then,begin if (topmenu == false) then,begin x := hero X(me) y := hero Y(me) d := hero direction(me) if (d == up) then(decrement(y)) if (d == left) then(decrement(x)) if (d == down) then(increment(y)) if (d == right) then(increment(x)) use NPC(NPC at spot(x,y)) end else, begin use menu item(selected menu item) end end if (key is pressed(Key:X)) then,begin if (top menu == false) then,begin main menu wait (1) end else,begin close menu(top menu) wait(1) end end end end
There are some problems though. For one, you can walk diagonally, and I can't think of an elegant way to prevent that. This also makes it possible to walk into a wall and get stuck.
Secondly, while the script works on the main menu and custom menus, it does not work on any of the built in menus for some reason. I think those menus may not allow scripts to run while they're open, but I'm not sure how to change that.
Third, it does not seem to work on items that close the menu. Hitting X again will close the menu, but hitting Z on the Close Menu item doesn't work.
So, uh, any suggestions?
The Mad Cacti: Wow. OK, we really need to add real customisation of input. To be honest, it shouldn't be all that much work...
For walking diagonally, I suggest an 'exit script' after each 'walk hero', like so:
if (key is pressed(Key:Up)) then (walk hero(me, up, 1), exit script)
I spot a bug in your script:
use NPC(NPC at spot(x,y))
'NPC at spot' returns 0 if there's no NPC on that tile, which will cause this to activate the first NPC of ID 0. And it's a bad idea to not do error checking for things like this anyway, because otherwise you'll get a script error message (eg. if there is no NPC 0) if your script error reporting level is turned up high enough.
There's nothing you can do about builtin menus. The rest of the engine pauses when any of them are open. In the future, they'll be rebuilt using slices (in the slice collections editor). Then scripts will be able to run during them (and we could add a command to simulate a keypress).
As for items not closing the menu, it seems you've discovered a whole string of bugs! Looking at the code, I can see that 'use menu item' is broken in a number of ways. I'm working on fixing that now.
The Mad Cacti: OK, bugs fixed; the fixes will be in the next nightly.
TheCube: Awesome! I think I fixed everything else, so it works nicely. I'll probly update the actual page sometime tomorrow with that, after I make it a bit prettier.
TheCube: I downloaded the nightly and Use Menu Item still doesn't work to close the menus. I opened it with the nightly custom and reimported the scripts, and saved again, but that didn't help either. Am I missing something? (Probably.) I'm using exactly the same script as in the article, except with Z and X.
Bob the Hamster: What is the date on your nightly build? The build system was broken since the 5th, and I only just fixed it at 9:00 AM this morning, so if you downloaded it before 9, you probably still have an old one without TMC's fixes.
TheCube: Aha! That would probably do it. Thanks! I'm at work, but I'll totally download that when I get home. Cool! And, uh, in the future, I will check the date instead of complaining. :D