Post Wednesday, 6th July 2016, 17:40

Safe move toggle questions

Edit: After messing around with it I found that ingame macros you create, and macros defined in your RC file don't play nice together. If you put any macro definitions in your rc (macros += M ] ===togglesafe) it will erase your existing macros, and will also prevent you from being able to save macros you made ingame. Alternatives I've found are: delete all macro definition lines in the code before copying over and define the macro ingame (===togglesafe works properly), use the alternate method where some keys are always safe and other keys are always regular movement, transfer the macros from the rc to the macro.txt file, or move all your macros into your rc file. I updated my post a bit below, highlighting some of my 'safe mode' solutions/examples.

MarvinPA wrote:
sanka wrote:Do you think it is possible to implement my old dream: that is *movement* keys that behave like this rest command, so that they are ignored when autoexplore would stop, so like when a monster is in view? I would use them for exploring when I do not want to autoexplore. A trigger to change normal function and explore mode would be ideal, but I could simply bind them to different keys than normal movement if this is not possible.

These also already exist (and there's a CMD_SAFE_WAIT in there too, rather than needing to use 01s). You can bind them with the bindkey option (I imagine you could theoretically set up some Lua to toggle between standard and safe movement, too).


This Marvin post spurred me to make a little script, but I had a couple questions.

Firstly, everyone set this in their rcfile if you want safe_wait:
  Code:
bindkey = [s] CMD_SAFE_WAIT

So now '.' is regular wait, and 's' is now safe_wait, which won't wait with enemies in view. Or whatever key you want to bind it to.

(edit: snip)

Is there a way to put variables from lua into non lua rc lines? (like with templating, bindkey = [h] CMD_{%lua var%}MOVE_LEFT).

I was also wondering if there would be a simple and non-obtrusive way to put a little flag or status on the screen when safe mode was on? Having a hard time finding this stuff.

Currently I'm using a lot of examples and github searching, which requires me to guess at what the function would be called, it would be nice if there was just a big list of all the lua functions and variables the rc has access to, even if it was undocumented.

-----------

Okay, there won't be a simple list of keycodes because they seem to vary, which complicates things. Even the \{13} for ctrl+m code binding doesn't work on my webtiles. I'll probably just use the ']' instead. Webtiles just sees numbers with numlock, so maybe I'll make that the template, on the off-chance someone else wants to use it.

My Webtiles safe mode movement toggle RC snippet:
http://pastebin.com/gFBcwQ7T (I was getting weird lua errors from cutting and pasting on my phone, I was able to fix them by going into pastebin, and clicking 'raw', and copying the 'raw' text instead)

Okay, tested on CAO, this code works for me. Starts/loads game with safemode off, ']' toggles safemode only for hjkl keys and keypad with numlock. This will only work for webtiles, everything else I've tried receives keycodes from the keypad. This won't work with numlock off, however, so be careful. (Adding those keys requires extra work, and macroing the keys to the hjkl keybindings, which I tried to explain below and also in the paste.)

A very easy alternative to this, especially for people who use primarily the keypad, is simply bindkey the hjkl keys to the safe moves, and simply use those keys for safe movement, and keypad for regular movement. Then we can all learn vim.

---------------------------------

If you want to bind (well, macro, actually) to like the keypad outside of webtiles, or to the arrow keys, or even control + key combinations, you need to use keycodes, as far as I know. Finding those keycodes is a pain in the butt, at least the method I've been using. I go ingame, hit '~' or ctrl+d, press 'm', then hit the key I want the keycode for. It should display in the textbox. Then escape out of the macro creating thing before creating a macro. Don't accidentally hit escape and get the escape keycode and rebind that.

The keycodes don't seem to work with bindkey, so my only solution is to macro the keypad keys to the hjkl keys. I have messed with it a bit, and it doesn't seem to have any side effects. We'll see.



Anyway, here's the sample code of my offline rc file. Couldn't bindkey on numpad, so had to macro the keypad keys to the hjkl keys. Chances are this won't work on any other setup without finding the keycodes with the ingame macro system, and replacing them in the macro definitions below. If you want to be able to bind macros while ingame, or using the macro.txt file, do your bindings there. If you bind them in the rc as in the example below, it will overwrite all non rc macro definitions every time you load.
  Code:
# toggle-able safe mode movement
###
# binding keypad keycodes to hjkl keys
macros += M \{-252} h
macros += M \{-249} y
macros += M \{-254} k
macros += M \{-246} u
macros += M \{-251} l
macros += M \{-245} n
macros += M \{-253} j
macros += M \{-248} b
: function startsafemode()
:   safemodeon = true
:   crawl.mpr("Safe mode on.")
bindkey = [b] CMD_SAFE_MOVE_DOWN_LEFT
bindkey = [h] CMD_SAFE_MOVE_LEFT
bindkey = [j] CMD_SAFE_MOVE_DOWN
bindkey = [k] CMD_SAFE_MOVE_UP
bindkey = [l] CMD_SAFE_MOVE_RIGHT
bindkey = [n] CMD_SAFE_MOVE_DOWN_RIGHT
bindkey = [u] CMD_SAFE_MOVE_UP_RIGHT
bindkey = [y] CMD_SAFE_MOVE_UP_LEFT
: end

: function stopsafemode()
:   safemodeon = false
:   crawl.mpr("Safe mode off.")
bindkey = [b] CMD_MOVE_DOWN_LEFT
bindkey = [h] CMD_MOVE_LEFT
bindkey = [j] CMD_MOVE_DOWN
bindkey = [k] CMD_MOVE_UP
bindkey = [l] CMD_MOVE_RIGHT
bindkey = [n] CMD_MOVE_DOWN_RIGHT
bindkey = [u] CMD_MOVE_UP_RIGHT
bindkey = [y] CMD_MOVE_UP_LEFT
: end

# initialize off
: stopsafemode()
: function togglesafe()
:   if safemodeon then
:     stopsafemode()
:   else
:     startsafemode()
:   end
: end

macros += M ] ===togglesafe

Pastebin of the same: http://pastebin.com/sqDdDunK