Can it be done, and if so, how? My googling skills have been exhausted, thanks for any help .
Ex
Variable name: test
Pattern to match: "blah @test blah"
So obviously, if test = "cheese",
"blah cheese blah" would match.
Hiroma tells you, "I just got to listen to someone complain about your deadly axekick being the bane of their existence." Archdragon Mizik Corten, Herald of Ruin says, "Man, that was a big axk." Hellrazor Cain de Soulis, Sartan's Hammer says, "Your [sic] a beast."
That more of a workaround, which is what I've been doing. In this case I would prefer actually just matching the variable itself. It would actually be better to just re-make the trigger every time the variable changes, with the variables value hard set into the pattern. That's still a workaround though, and is poor coding IMO.
I'm not sure what it is you're asking for. Why would you need to remake the trigger? The whole point of a variable is that it is variable... or am I missing something? :-/
Hiroma tells you, "I just got to listen to someone complain about your deadly axekick being the bane of their existence." Archdragon Mizik Corten, Herald of Ruin says, "Man, that was a big axk." Hellrazor Cain de Soulis, Sartan's Hammer says, "Your [sic] a beast."
I don't want the trigger to "trigger" for every possible match, then use if statements after the fact. I only want the trigger to fire if it actually matches the variable. There is a big difference, time wise.
In zMud, I could use #Trigger trig_highlight_target {@target} {#co ....}, and that was fine. I didn't have to make a trigger that fired on every single word sent from the mud and then use an #if to see if it matched @target.
It's not possible to include a variable in a pattern. AFAIK, allowing Mudlet to be capable of this would make trigger matching as a whole less efficient.
So you still have to decide between a wildcard trigger and checking it against a variable afterwards, or a temp trigger that is re-created any time your variable changes.
Both choices will work, however I think a temp trigger will be far more efficient, even if sloppy. Thanks peeps.
As a side note, can you group things in a ? in regex pattern matching? As in, an all or nothing "might appear, might not" phrase?
For instance, alias "fs" (for farsee) is ^fs\s(\S). To make it work with either "fs" alone, or "fs Sarapis", I made it ^fs\s?(\S)?. However, this has the unintentional side-effect of allowing "fsh" actually trigger the alias. This is messing up several of my short aliases (alias 't' for example). What I'd like to do is put the ? attachment on the \s(\S) all together in one "block". Can this be done?
The (\w+) here captures the argument, if you use one. The (?: )? around it makes it, plus a leading space, optional, while ensuring that this outer block isn't also captured by use of the ?: modifier.
Fantastic, thanks Iocun. I started using \S because I incorrectly thought \w+ included white space (which it doesn't). \w+ works fine . So do the ?: brackets. Thanks!
There are better ways of doing this, as have been noted above, but, you should try this one.
test = "cheese"
Alias regex: ^blah (\w+) blah$
f = loadstring("return " .. matches[2])
echo(f())
Should print "cheese" if we put in "blah test blah".
Mind you, I have a full Lua implementation on my machine. I'm not sure if loadstring() is available in the streamlined version of Lua packaged with Mudlet.
There are better ways of doing this, as have been noted above, but, you should try this one.
test = cheese
Alias regex: ^blah (\w+) blah$
f = loadstring("return " .. matches[2])
echo(f())
Should print "cheese" if we put in "blah test blah".
Mind you, I have a full Lua implementation on my machine. I'm not sure if loadstring() is available in the streamlined version of Lua packaged with Mudlet.
If test is a global variable, I believe you could accomplish the same thing with:
There are better ways of doing this, as have been noted above, but, you should try this one.
test = cheese
Alias regex: ^blah (\w+) blah$
f = loadstring("return " .. matches[2])
echo(f())
Should print "cheese" if we put in "blah test blah".
Mind you, I have a full Lua implementation on my machine. I'm not sure if loadstring() is available in the streamlined version of Lua packaged with Mudlet.
If test is a global variable, I believe you could accomplish the same thing with:
echo(_G[matches[2]])
Ah, cool. There's a table with all global variables.
Mind you, I have a full Lua implementation on my machine. I'm not sure if loadstring() is available in the streamlined version of Lua packaged with Mudlet.
Lua available in Mudlet is not cut down in any manner.
Mind you, I have a full Lua implementation on my machine. I'm not sure if loadstring() is available in the streamlined version of Lua packaged with Mudlet.
Lua available in Mudlet is not cut down in any manner.
Ah, I was having difficulty with the socket library once. Though, I think that's part of the extended libraries, not the core implementation.
Comments
Archdragon Mizik Corten, Herald of Ruin says, "Man, that was a big axk."
Hellrazor Cain de Soulis, Sartan's Hammer says, "Your [sic] a beast."
Archdragon Mizik Corten, Herald of Ruin says, "Man, that was a big axk."
Hellrazor Cain de Soulis, Sartan's Hammer says, "Your [sic] a beast."
In zMud, I could use #Trigger trig_highlight_target {@target} {#co ....}, and that was fine. I didn't have to make a trigger that fired on every single word sent from the mud and then use an #if to see if it matched @target.
Big difference there.
→My Mudlet Scripts
As a side note, can you group things in a ? in regex pattern matching? As in, an all or nothing "might appear, might not" phrase?
For instance, alias "fs" (for farsee) is ^fs\s(\S). To make it work with either "fs" alone, or "fs Sarapis", I made it ^fs\s?(\S)?. However, this has the unintentional side-effect of allowing "fsh" actually trigger the alias. This is messing up several of my short aliases (alias 't' for example). What I'd like to do is put the ? attachment on the \s(\S) all together in one "block". Can this be done?
→My Mudlet Scripts
if matches[2] ~= nil then
send("farsee "..matches[2],false)
else
send("farsee "..target,false)
end
send("farsee " .. (matches[2] or target))
Much easier than an if construct.
→My Mudlet Scripts
Svof
Mudlet Discord join up
Svof
Mudlet Discord join up
Svof
Mudlet Discord join up