Page 1 of 1

How do I add the Enter key in a macro?

PostPosted: Saturday, 28th July 2018, 16:02
by RoGGa
I'm trying to set up a macro for specific skills targets at the start of a game.
I can do a macro with the following:
  Code:
#for F1 key
M:\{-1073741882}
A:m=a10
and then manually press the Enter key after F1.
But I'd like to set four skills training targets in 1 key stroke.

I've tried adding: {13} or ! to the macro but it doesn't work.
Any help is appreciated.

Re: How do I add the Enter key in a macro?

PostPosted: Saturday, 28th July 2018, 18:51
by Fingolfin
I don't know about your specific implementation, but there is a lua binding for setting and getting skill targets :
http://csclub.uwaterloo.ca/~ebering/crawl/lua/modules/you.html#set_training_target
https://github.com/crawl/crawl/commit/a7893f84d51c6200db5bcee0da5e6e7b0b3324e2

Re: How do I add the Enter key in a macro?

PostPosted: Saturday, 28th July 2018, 21:46
by RoGGa
I've tried the following without success:
  Code:
M:\{-1073741882}
A:===set_training_target(Fighting, 9)

or
  Code:
M:\{-1073741882}
A:===you.set_training_target(Fighting, 9)

There isn't a reference to Lua in the file: \docs\macros_guide.txt
and what I found about Lua in: \docs\options_guide.txt
wasn't very helpful.

Re: How do I add the Enter key in a macro?

PostPosted: Sunday, 29th July 2018, 00:11
by Fingolfin
What you could do is put it all in the ready() function and condition it to only run once :

  Code:
{
local is_first_turn = true

function ready()
  if is_first_turn then
    -- set your training targets here
    is_first_turn = false
  end
end
}


It's not very elegant, but it should do what you want.

Re: How do I add the Enter key in a macro?

PostPosted: Sunday, 29th July 2018, 00:25
by Fingolfin
Wait no this is wrong. I tried :
  Code:
{
local is_first_turn = true

function ready()
  if is_first_turn then
    you.set_training_target('Fighting', 9)
    is_first_turn = false
  end
end
}


and it works fine, but it executes every time you load the game, not once per game.

You want to do :

  Code:
{
function ready()
  if you.turns() == 0 then
    you.set_training_target('Fighting', 9)
  end
end
}


This works as intended.

P.S. Don't forget the quotes around the name of the skill, it won't work without them.

Re: How do I add the Enter key in a macro?

PostPosted: Sunday, 29th July 2018, 01:36
by RoGGa
Great! ...and ty so much

So just for others to know, I copied your code to my init.txt file since I play WinTiles offline.

Re: How do I add the Enter key in a macro?

PostPosted: Sunday, 29th July 2018, 15:35
by advil
I think doing this with lua is better, but
  Code:
\{13}
should work for enter (the backslash before { is necessary for a key code). I tested the following macro and it seemed to do the right thing:
  Code:
m=a10\{13}\{27}

Re: How do I add the Enter key in a macro?

PostPosted: Sunday, 29th July 2018, 15:54
by RoGGa
advil wrote:
  Code:
m=a10\{13}\{27}

TY! I'm pretty sure I had tried that but obviously didn't get the same result as you. Might have put a slash / instead of a \.

I think this option is the better of the two since the Lua ready() function seems to me like it is called every time it is the player's turn to enter something.
Ideally, a better option would be a Lua function that is called once at the start of a new game and never called again.

Thanks again to both of you for the learning opportunity.

Re: How do I add the Enter key in a macro?

PostPosted: Sunday, 29th July 2018, 15:59
by advil
RoGGa wrote:I think this option is the better of the two since the Lua ready() function seems to me like it is called every time it is the player's turn to enter something.
Ideally, a better option would be a Lua function that is called once at the start of a new game and never called again.


It is, but there's no real cost to that. An implementation of the other hook you suggest would be effectively identical to the "if turns = 0" check Fingolfin gave you above.

Re "ready()", ebering has put together some documentation of the current set of lua hooks here.