Varsuuk
January 5th, 2021, 04:37
I HAVE looked at
https://www.lua.org/pil/20.2.html
https://lua-users.org/wiki/PatternsTutorial
https://www.lua.org/manual/5.3/manual.html#6.4.1
and I still *bleep* at anything beyond trivial.
I'd like to have this:
/swthac0
/swthac0 [ranged]
/swthac0 [ranged,magic]
I could not get ANYWHERE with [], so even (ranged,magic) would be OK - but really I JUST wanted what was INSIDE of them - so I switched to doing:
/swthac0 ranged,magic
In MoreCore, the cliroller thing has "Melee Attack" in top title and "/swthac0 ranged,magic" in Dice String
I hoped I could apply a regex to the incoming: "ranged,magic Melee Attack"
Where it would result in:
sAttributes = "ranged,magic"
sRollName = "Melee Attack"
The original start point to grab ostensibly the disc-string along with the AUTOMATICALLY appended to the disc string by the MoreCore caller of performAction() was:
local _, _, sAttributeParam, sRollName = string.find(sParams, "([^%s]+)%s*(.*)");
My skills fail when corner cases are looked at.
Passing: /swthac0 ranged,magic -> works
Passing: /swthac0 ranged -> works
Passing: /swthac0 -> Results in:
sAttributes = "Melee"
sRollName = "Attack"
I played around with using (%b[]) and (%b()) and while the latter (no love with []) matched, it of course returns the "(" and ")" as part of it too.
I have read that cannot make patterns optional so I realize why other things I tried failed.
How would I approach this?
The above split of Melee and Attack happens even in the default /thac0 handler because it later tries to see if it has an actual roll string (required in normal /thac0 like "1d20x19") and if it does not, it doesn't interpret the first argument - just concatenates them together. So it "works" :)
In my case, it would try to treat the first melee as an attrib.
There some ways I can theoretically imagine:
1) Require a () around the attributes, like "%(([^%s]+)%)" [Haven't tested that, would PREFER to use "[]" if I HAD to use a grouper.] then look for that first, if find it, continue from where leaves off to read the rest like "%s*(.*)" --- so 1 to 2 different finds.
2) Require the user to name rolls with a grouping delim (again can't use [] so far so would be "(Melee Attack)"). -- but this smells to HIGH HEAVEN!
3) Require a damn terminator whether or not there is anything to separate :( like:
/swthac0 |
/swthac0 ranged|
/swthac0 ranged,magic|
I will try #3 first as a starting point that looks like I might have success - I man posting already even before know if can get #3 to do what need because I am so bad at this, if I waited until knew if that was an option I might not post in time tonight to get feedback.
Assuming bracketing with [] is a pain, I would enter:
/swathac0
/swthac0 ranged
/swthac0 ranged,melee
and this regex would give me
"", "Melee Attack" or "Melee Attack", ""
"ranged" "Melee Attack"
"ranged,melee" "Melee Attack"
in the 2 results.
https://www.lua.org/pil/20.2.html
https://lua-users.org/wiki/PatternsTutorial
https://www.lua.org/manual/5.3/manual.html#6.4.1
and I still *bleep* at anything beyond trivial.
I'd like to have this:
/swthac0
/swthac0 [ranged]
/swthac0 [ranged,magic]
I could not get ANYWHERE with [], so even (ranged,magic) would be OK - but really I JUST wanted what was INSIDE of them - so I switched to doing:
/swthac0 ranged,magic
In MoreCore, the cliroller thing has "Melee Attack" in top title and "/swthac0 ranged,magic" in Dice String
I hoped I could apply a regex to the incoming: "ranged,magic Melee Attack"
Where it would result in:
sAttributes = "ranged,magic"
sRollName = "Melee Attack"
The original start point to grab ostensibly the disc-string along with the AUTOMATICALLY appended to the disc string by the MoreCore caller of performAction() was:
local _, _, sAttributeParam, sRollName = string.find(sParams, "([^%s]+)%s*(.*)");
My skills fail when corner cases are looked at.
Passing: /swthac0 ranged,magic -> works
Passing: /swthac0 ranged -> works
Passing: /swthac0 -> Results in:
sAttributes = "Melee"
sRollName = "Attack"
I played around with using (%b[]) and (%b()) and while the latter (no love with []) matched, it of course returns the "(" and ")" as part of it too.
I have read that cannot make patterns optional so I realize why other things I tried failed.
How would I approach this?
The above split of Melee and Attack happens even in the default /thac0 handler because it later tries to see if it has an actual roll string (required in normal /thac0 like "1d20x19") and if it does not, it doesn't interpret the first argument - just concatenates them together. So it "works" :)
In my case, it would try to treat the first melee as an attrib.
There some ways I can theoretically imagine:
1) Require a () around the attributes, like "%(([^%s]+)%)" [Haven't tested that, would PREFER to use "[]" if I HAD to use a grouper.] then look for that first, if find it, continue from where leaves off to read the rest like "%s*(.*)" --- so 1 to 2 different finds.
2) Require the user to name rolls with a grouping delim (again can't use [] so far so would be "(Melee Attack)"). -- but this smells to HIGH HEAVEN!
3) Require a damn terminator whether or not there is anything to separate :( like:
/swthac0 |
/swthac0 ranged|
/swthac0 ranged,magic|
I will try #3 first as a starting point that looks like I might have success - I man posting already even before know if can get #3 to do what need because I am so bad at this, if I waited until knew if that was an option I might not post in time tonight to get feedback.
Assuming bracketing with [] is a pain, I would enter:
/swathac0
/swthac0 ranged
/swthac0 ranged,melee
and this regex would give me
"", "Melee Attack" or "Melee Attack", ""
"ranged" "Melee Attack"
"ranged,melee" "Melee Attack"
in the 2 results.