Answered

Post Reply
littlexblue
Posts: 2
Joined: Mon Sep 01, 2014 8:40 pm

Answered

Post by littlexblue »

Hey, all.

I have a question for you that's probably fairly simple, but I haven't been able to find the answer for it.

I'm wondering how to create an alias using a wildcard that may or may not have a value...let me give an example, because as mentioned, I'm not sure how to explain this clearly.

My alias would be:

^x (\w+)

And the script would basically cause it so that when I entered 'x guard' it would, for general purposes let's say, set my variable to whatever follows 'x', and then attack it. So my script would be:

target == matches[2]
send("kill "..target)

My question is, is it possible, and if so, how can I get it to allow me to enter just 'x' by itself and have it skip the variable assignment and go right to 'kill'ing the same target, without writing separate alias. I understand the basics of if then statements, and that I may need one, but I just don't know how to go about it.

I hope I managed to make that clear enough :?
Last edited by littlexblue on Fri Sep 05, 2014 2:24 am, edited 2 times in total.

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: HOWTO: Idk how to even say this without explaining...

Post by icesteruk »

^x ?(\w*)$

if matches[2] == "" then
send("kill " .. target)
else
target = matches[2]
send("kill " .. target)
end


x bob ... will target bob then kill ..

x ... will kill whatever you have targetted.

Hope that helps!

littlexblue
Posts: 2
Joined: Mon Sep 01, 2014 8:40 pm

Re: HOWTO: Idk how to even say this without explaining...

Post by littlexblue »

That's what I was looking for!

Thank you so much ^.^

So the ? before the wildcard is just saying, this may be here, and it may not, then?

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Answered

Post by SlySven »

No: it is referring to the space character after the initial x, but it is IIRC saying "matches zero or one instance(s)", the capture group (which becomes matches[2]) is \w "match any NON-whitespace character" combined with the "*" afterwards which means "match zero or more instances of the previous item (the '\w')".

That does mean that the captured item is ONLY ONE WORD. If you tried "x spot the dog" it would not be triggered because there is more stuff on the end that would not fit the pattern (the '$' requires the pattern to end after the first group of non-whitespace characters i.e. the first word) so even a trailing space i.e. "x spot " would mean it doesn't match either.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Answered

Post by Jor'Mox »

You can also use: ^x(?: (\w+))?$ as a pattern. The main difference is that this pattern will not accept single words that start with x, i.e. xylophone won't trigger this pattern, but it will trigger ^x ?(\w*)$.

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: Answered

Post by icesteruk »

Jor'Mox wrote:You can also use: ^x(?: (\w+))?$ as a pattern. The main difference is that this pattern will not accept single words that start with x, i.e. xylophone won't trigger this pattern, but it will trigger ^x ?(\w*)$.

no it doesnt.. what I posted I have ^c ?(\w+)$ and whenever I type C words it doesnt trigger...

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Answered

Post by Jor'Mox »

They would need to be the first and only word typed in as a command. So, if you had one that used "s", and then typed "stand", your alias would be triggered, with "tand" as the argument. It wouldn't trigger if you typed them as part of a larger command with multiple words, due to the only allowed space being right after the first character.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Answered

Post by demonnic »

Jor'Mox is correct, and trust me when this sort of thing happens to you it can be a bear to track down, especially if you rarely type things like xylophone on a line on its own. Then you may be dealing with an alias you made years back and have no reason to suspect in your immediate efforts. Tends to not happen so much after the first time you get caught out by it though.

Post Reply