How do I add the Enter key in a macro?


Problems running or configuring the software, commands & options, compiling, different platforms, using the interface, documentation, etc.

User avatar

Spider Stomper

Posts: 187

Joined: Thursday, 6th November 2014, 17:19

Location: Canada

Post Saturday, 28th July 2018, 16:02

How do I add the Enter key in a macro?

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.

Slime Squisher

Posts: 344

Joined: Tuesday, 14th April 2015, 19:56

Location: France

Post Saturday, 28th July 2018, 18:51

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

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
3 runes : MiMo^Ru, HOFi^Beogh, TrMo^Yredelemnul, GrFi^Ru, FoFi^Gozag, MiGl^Okawaru
4 runes : DDFi^Makhleb
5 runes : GrEE^Vehumet
15 runes : MiFi^Ru, NaWz^Sif Muna, GrWz^Sif Muna
I mostly play offline or online on CXC

For this message the author Fingolfin has received thanks:
RoGGa
User avatar

Spider Stomper

Posts: 187

Joined: Thursday, 6th November 2014, 17:19

Location: Canada

Post Saturday, 28th July 2018, 21:46

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

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.

Slime Squisher

Posts: 344

Joined: Tuesday, 14th April 2015, 19:56

Location: France

Post Sunday, 29th July 2018, 00:11

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

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.
3 runes : MiMo^Ru, HOFi^Beogh, TrMo^Yredelemnul, GrFi^Ru, FoFi^Gozag, MiGl^Okawaru
4 runes : DDFi^Makhleb
5 runes : GrEE^Vehumet
15 runes : MiFi^Ru, NaWz^Sif Muna, GrWz^Sif Muna
I mostly play offline or online on CXC

Slime Squisher

Posts: 344

Joined: Tuesday, 14th April 2015, 19:56

Location: France

Post Sunday, 29th July 2018, 00:25

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

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.
3 runes : MiMo^Ru, HOFi^Beogh, TrMo^Yredelemnul, GrFi^Ru, FoFi^Gozag, MiGl^Okawaru
4 runes : DDFi^Makhleb
5 runes : GrEE^Vehumet
15 runes : MiFi^Ru, NaWz^Sif Muna, GrWz^Sif Muna
I mostly play offline or online on CXC

For this message the author Fingolfin has received thanks:
RoGGa
User avatar

Spider Stomper

Posts: 187

Joined: Thursday, 6th November 2014, 17:19

Location: Canada

Post Sunday, 29th July 2018, 01:36

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

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.

For this message the author RoGGa has received thanks:
Fingolfin

Dungeon Master

Posts: 388

Joined: Monday, 18th August 2014, 20:04

Post Sunday, 29th July 2018, 15:35

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

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}

For this message the author advil has received thanks:
RoGGa
User avatar

Spider Stomper

Posts: 187

Joined: Thursday, 6th November 2014, 17:19

Location: Canada

Post Sunday, 29th July 2018, 15:54

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

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.

Dungeon Master

Posts: 388

Joined: Monday, 18th August 2014, 20:04

Post Sunday, 29th July 2018, 15:59

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

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.

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 15 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.