Page 2 of 3

Re: Flexible offensive aliases

Posted: Wed Jan 13, 2010 7:02 pm
by juraj
Thanks!

Re: Flexible offensive aliases

Posted: Mon Feb 08, 2010 5:36 am
by naftali
Heiko wrote:a = b or c means: if b is undefined i. e. b = nil, then a = c

At the time the original posting was written matches[3] would have been undefined if capture group #2 was empty.
Today, this behaviour has been changed. All capture groups in the regex will be defined and empty capture groups will contain an empty string i.e. "". When the original post was written a script like send( matches[3] ) would have caused a Lua error whenever capture group #2 was empty.

Code: Select all

t = "hello"
send( matches[3] or t )
sent the default value "hello" in case matches[3] was empty. That was the whole point of the expression. Today, it's meaningless in this respect. Today you can make good use for this sort of expression when initializing variables e.g.

Code: Select all

b = c or 0
-> if c is undefined at the time this script is run, initialize it to 0 instead of causing a Lua runtime error.
This being the case, how would you remake the original alias? Is there a better way then using the following?

Code: Select all

if not matches[3]=="" then blah end

Re: Flexible offensive aliases

Posted: Mon Feb 08, 2010 1:41 pm
by Heiko
Today you can simply write

Code: Select all

send( "kick" .. matches[2] .. matches[3] )

Re: Flexible offensive aliases

Posted: Mon Feb 08, 2010 1:46 pm
by naftali
What if it is not a choice between variables? For instance if I have a script that sets a variable (x) where if matches[5] exists then x=matches[5] and if it does not x=0.

Re: Flexible offensive aliases

Posted: Sun Feb 14, 2010 6:36 am
by Omni
I like, but don't understand. Could I get a quick recap for those that don't understand all this. And the exact code for this. I want to make use of it. I seriously need to take the time to learn to understand all this.

Re: Flexible offensive aliases

Posted: Sun Feb 14, 2010 1:59 pm
by Vadi
Hm... does 'For example, our alias "dd" will either kick the target when you just do "dd", or kick a rat when you "dd rat".' help?

Re: Flexible offensive aliases

Posted: Sun Feb 14, 2010 10:19 pm
by Denarii
naftali wrote:What if it is not a choice between variables? For instance if I have a script that sets a variable (x) where if matches[5] exists then x=matches[5] and if it does not x=0.
Code: [show] | [select all] lua
x = matches[5] or 0
Now if you wanted to make it so that it set the variable to matches[5] if it exists AND is not an empty string without resorting to an if statement, it's slightly more complicated.
Code: [show] | [select all] lua
x = ((matches[5] ~= "") and matches[5]) or 0

Re: Flexible offensive aliases

Posted: Sun Feb 21, 2010 2:49 pm
by Caled

Code: Select all

function pChk(wildcard, default)
    local result = default
    if wildcard ~= "" then result = wildcard end
    return result
end
In your trigger, put:
x = pChk(matches[5], 0)

Re: Flexible offensive aliases

Posted: Thu May 06, 2010 8:59 pm
by Erudite
This might be a sad question to ask, but as a horrid programmer, and rather new to Lua, I cannot figure this out. Say I wanted to create an Alias for "strike <target> Neck" While I have issues with just using target already, is there a way to script it to be flexible?

Re: Flexible offensive aliases

Posted: Fri May 07, 2010 11:52 am
by Knute
You can easily script that, depending upon how flexible you want it to be.

So let's say that you have 2 variables: target and bodypart
target is the one you want to attack.
bodypart is say neck or head or whatever.

You can set up an alias to set either of them.

The code would look something like:

Code: Select all

send("strike " .. target .. " " .. bodypart)
Notice that there is a space after strike, and another space in between target and bodypart in the quotes. That is necessary to prevent the output to be sent as "strike<target>Neck" rather than "strike <target> Neck" as the concat function (the two dots) doesn't add spaces so we have to add them manually in the script.

HTH