Changing Accelerators by Groups

Posted by Myrilith on Sat 20 Oct 2007 11:39 PM — 6 posts, 24,224 views.

#0
I run MUSHClient from a laptop keyboard, so I'm missing the keypad to use for simple directions. I've worked out a system of Accelerators to make up for this, usually along the lines of

Accelerator "CTRL+8", "north"


I've also got a secondary set of accelerators to meet some of the common functions, and these are like

Accelerator "CTRL+ALT+8", "drink mana"


What I'm trying to do is establish a kind of group of accelerators, so that I can change modes and thus change the keybindings. For example, the CTRL+ALT+8 combination would
drink mana
if I was in, say, "Magic" mode, but if I was in "Combat" mode it would
drink health
instead. I also have a third Debate mode.

I've worked out a system using an accel_mode variable and if-then statements to adjust what set of actions my accelerators perform. The problem that I'm running into is that if I have to re-process the script every time I change modes, or it won't register the change. It looks something like this:

if GetVariable ("accel_mode") = "combat" then
 Accelerator "CTRL+ALT+8", "drink health"
end if

if GetVariable ("accel_mode") = "magic" then
 Accelerator "CTRL+ALT+8", "drink mana"
end if

if GetVariable ("accel_mode") = "debate" then
 Accelerator "CTRL+ALT+8", "drink bromide"
end if


If I switch modes and then re-process, it will do whichever set of actions accompanies the mode I'm in. But if I don't reprocess, I can switch modes as many times as I want and it will only do one set, the mode that was in place the last time the script was processed.

There -has- to be a better way to do this. ^.^ (BTW, I've also tried using ELSE IF statements, but didn't have any success at all with it.) What can I do?
Australia Forum Administrator #1
How do you switch modes? This seems like the time to redo the accelerators.

Another way would be to make generic aliases that decide at the last moment what to do, eg.


Accelerator "CTRL+ALT+8", "ctrl+alt+8_alias"


Now make an alias which matches on "ctrl+alt+8_alias" and have it make the decision in its script (based on your current mode).

However I think it is simpler just to redo the group of accelerators at the moment you change modes.
#2
Ha! That's fantastic, Nick. For some reason, I thought that accelerators had to be loaded in some sort of world-wide script, like the one I load on startup.

It fixed a world of problems -- with this and several other things -- knowing that accelerators can be changed spontaneously like other scripts, they don't have to be... preserved... anywhere. Thanks!
#3
Okay, that worked. I went on, crafted almost the entirety of my system, and now I'm coming back to this:

Is there any way to send Accelerator commands into the command history? If it's a simple statement then I can do it without any trouble by using
Accelerator "ALT+9","/SendPush ""say Hello!"""
Several of my accelerators, though, are set to fire an alias, and I can't get these aliases to work.

For example, if I had an alias "sayhi" that would send "say Hello!" to the world, it doesn't work to use
Accelerator "ALT+9","/SendPush ""sayhi"""
I can't get it to recognize that this is an alias. (BTW, I know it's a valid alias, because it works if I type it directly into the command window.)

Is there any way to make an Accelerator send an alias both into the command history and to execute immediately?
Russia #4
The alias could do a sequence of PushCommand();SetCommand("alias itself");PushCommand(), to clear the command window, add its own match text to the window, and then clear it again, pushing itself into the command history.

If you want to keep the original text in the command window, then I suppose something like this should do it:


prev_command = GetCommand()
SelectCommand()
PasteCommmand("alias")
PushCommand()
SetCommand(prev_command)

#5
Oh, okay -- I think I get it.

So I should set the alias itself to put the command in the history. Instead of just setting the alias to send "say Hello!" to the World, send something like "world.sendPush "say Hello!"" to Script.

Again, a simple solution. ^.^ Thanks.