strfind() - doesn't like my regexes

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

User avatar
Mrugnak
Dragon
Posts: 745
Joined: Mon Jul 21, 2008 7:38 pm

strfind() - doesn't like my regexes

Post by Mrugnak »

I want to preface this with the point that I write regexes for my dayjob, but they're in perl or C#. I don't have a clue what dialect MapTools is using and I think this is my problem.

If I do
[h: id = strfind("8d6+4", "(\\d+)")]
[getGroup(id, 1, 0)]<br>
[getGroup(id, 2, 0)]<br>
[getGroup(id, 3, 0)]<br>

Maptools does what I expected and returns

8
6
4

But if I do
[h: id = strfind("8d6+4", "(\\d+)d6")]

Maptools can't find anything. Some of the wiki examples are much more complex and include string literals, so why the flibbertijibbet is this not a thing? :(


User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: strfind() - doesn't like my regexes

Post by jfrazierjr »

Mrugnak wrote:I want to preface this with the point that I write regexes for my dayjob, but they're in perl or C#. I don't have a clue what dialect MapTools is using and I think this is my problem.

If I do
[h: id = strfind("8d6+4", "(\\d+)")]
[getGroup(id, 1, 0)]<br>
[getGroup(id, 2, 0)]<br>
[getGroup(id, 3, 0)]<br>

Maptools does what I expected and returns

8
6
4

But if I do
[h: id = strfind("8d6+4", "(\\d+)d6")]

Maptools can't find anything. Some of the wiki examples are much more complex and include string literals, so why the flibbertijibbet is this not a thing? :(
nm.. I am a monkeys uncle and did not pay attention to the details... forest for the trees sort of thing...
Last edited by jfrazierjr on Wed Jan 18, 2017 8:44 am, edited 1 time in total.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: strfind() - doesn't like my regexes

Post by wolph42 »

No thats not True. 8d6 does not contain a + nor -. I think you've been led astray by the \\d+ which means 'digit' and not 'd'

your regex suggestion
"(\\d+?)[-+]d6"
would hence at least required
8+d6 or 8-d6 to match. And would allow for e.g. 8d+d6 to match as well (due to the ?).

@OP: your regex is solid, so there are so far i can see only 2 options: you retrieve an incorrect match and group as you don't show this I can't tell. OR: MT has issues...

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: strfind() - doesn't like my regexes

Post by aliasmask »

I think you just need to put a 1 where the 0 is to get the proper return value. Using a 0 for group return, returns the entire matching string while using 1 returns the first group of the matching string.

[h: id = strfind("8d6+4", "(\\d+)d6")]
[getGroup(id, 1, 0)]
[getGroup(id, 1, 1)]

returns
8d6
8

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: strfind() - doesn't like my regexes

Post by aliasmask »

To get a dice expression and divide it up in to its component parts, I would do this assuming this format 1d6+1.

Code: Select all

[H: regex = "(?i)(\\d+)d(\\d+)([+-]\\d+)?"]
[H: diceExpStr = "4d6+4"]
[H: id = strfind(diceExpStr,regex)]
[H: numDice = getGroup(id,1,1)]
[H: sides = getGroup(id,1,2)]
[H: modifier = getGroup(id,1,3)]
[H, if(json.isEmpty(modifier)): modifier = 0]
[R: strformat("Dice: %{numDice}; Sides: %{sides}; Mod: %{modifier}")]

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: strfind() - doesn't like my regexes

Post by jfrazierjr »

aliasmask wrote:I think you just need to put a 1 where the 0 is to get the proper return value. Using a 0 for group return, returns the entire matching string while using 1 returns the first group of the matching string.

[h: id = strfind("8d6+4", "(\\d+)d6")]
[getGroup(id, 1, 0)]
[getGroup(id, 1, 1)]

returns
8d6
8
This... for some odd reason, java returns the first item in the "group" as the matching string, not the first grouping (ie, your first outer parenthesis). This is one thing that has always perplexed me(coming from Perl) with Java and other implementations of regex. It's something I have to fight with when writing java because it's not what how I learned regex 15+ years ago(not in java).
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
Mrugnak
Dragon
Posts: 745
Joined: Mon Jul 21, 2008 7:38 pm

Re: strfind() - doesn't like my regexes

Post by Mrugnak »

Thanks for the help everyone. Aliasmask, thank you very much in particular for the code snippet; and jfrazierjr - yeah, perl brain goes whaaaaat? :P

The whole point behind this is that I'm making a macro for explosion damage in GURPS, which is one of those game rules that are interesting but not-very-good to actually play out with pen-n-paper. But they're GREAT with a computer doing the scutwork :P

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: strfind() - doesn't like my regexes

Post by jfrazierjr »

Mrugnak wrote:Thanks for the help everyone. Aliasmask, thank you very much in particular for the code snippet; and jfrazierjr - yeah, perl brain goes whaaaaat? :P

The whole point behind this is that I'm making a macro for explosion damage in GURPS, which is one of those game rules that are interesting but not-very-good to actually play out with pen-n-paper. But they're GREAT with a computer doing the scutwork :P

am I remembering right that GURPS(almost like RoleMaster) has like several hundred tables? Last time I looked at either of those (more time with Rolemaster... but that's not saying much) was in the 80's.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

Michael Silverbane
Cave Troll
Posts: 44
Joined: Fri Feb 02, 2007 1:40 am
Location: Columbia, MO

Re: strfind() - doesn't like my regexes

Post by Michael Silverbane »

Not quite. There is a lot of complexity (or the potential for a lot of complexity) baked into GURPS, but it doesn't refer to tables as much as Rolemaster does.

I would say that there are maybe a dozen or so tables spread throughout the GURPS game, but mostly, you'll be referring to only four of them with any regularity (hit locations, critical effects, reactions, and the speed/range tables).
It's a big world out there. Go tear it up.

User avatar
Mrugnak
Dragon
Posts: 745
Joined: Mon Jul 21, 2008 7:38 pm

Re: strfind() - doesn't like my regexes

Post by Mrugnak »

In my experience the various editions of D&D have more lookup tables. What you might be remembering is that the character creation system is about as fiddly as Hero System (each in their own special way :) ). That doesn't have tables so much as loooong shopping lists. So looking at the big list of weapons, which is tables can perhaps make your eyes roll back in your head, but I don't know of many RPGs that have avoided weapons tables entirely without going completely narrative or on combat resolution.

But once you're in play there really isn't much in the way of tables - about four, as Michael said, and it's not like you need to reference them on every hit.
Hit locations are completely optional - even if your GM is using them, you can just choose to hit "the torso" and go on your merry way never looking it up again.
Speed/Range table almost never comes up for melee combatants - but it does come up regularly for ranged combat, so if you're in a modern-day game with guns, you might get pretty familiar with it. There's an option to use a shorter "range band" table like the D&D ranges but that's still a table.
Reaction table comes up when the GM doesn't really know/care how the NPC reacts; if that NPC hates elves and thinks they're hideous insect-eyed freaks, your elf just is never going to have a good reaction with them. You only look at it periodically too.
As for critical hits/misses, like in D&D they're rare (~0.5% to 6% of rolls), and very unlike Rolemaster you don't have a separate table for critical hit with a "swung impaling long-handled weapon, left handed" vs "swung impaling long-handled weapon, right handed" (I kid because I respect and love). They do have a separate critical failure for Unarmed (because "drop weapon" or "weapon becomes unready" is nonsensical) and they indulged in a separate critical hit table for head blows because head trauma is aweful. Critical Hits are optional, and I think the Critical Head Blow table itself is optional.

Basically there's a lot of options in GURPS. It borders on a "build your own roleplaying game" system - not as severe as FUDGE.

taustinoc
Dragon
Posts: 516
Joined: Mon Aug 03, 2015 6:30 pm

Re: strfind() - doesn't like my regexes

Post by taustinoc »

Mrugnak wrote:you don't have a separate table for critical hit with a "swung impaling long-handled weapon, left handed" vs "swung impaling long-handled weapon, right handed" (I kid because I respect and love).
Sadly, even F.A.T.A.L. doesn't go quite that far, even with 36 critical hit tables. (There is one result that involved female circumcision, though.)

Note: You do not want to look this game up. It is, hands down, the most offensive game ever published, including Racial Holy War.

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: strfind() - doesn't like my regexes

Post by jfrazierjr »

must RoleMaster I was thinking of. I had played about half to a dozen games using MERP(Middle Earth Role Playing) which at the time was "Role Master Lite" and by "lite" and by lite that means about 5% less rules than Role Master which at the time was stupidly chart/table crazy.

There were some 30-50 or more results on multiple tables depending on if you were using spell(seperated tables for fire, cold, electric, etc), piercing, bludgeoning, or slashing weapons. Of course, it was all super descriptive. Way to super detailed for me.... However, this would be an incredible system to utilize in maptool(if players are willing to take the chance of one hit killing them or permently disabling a body part!!!!) with the various data lookup tools we have... it could be done in seconds and never a player looking at a table other than loading it in the first time data dump.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
Mrugnak
Dragon
Posts: 745
Joined: Mon Jul 21, 2008 7:38 pm

Re: strfind() - doesn't like my regexes

Post by Mrugnak »

GURPS has the same detail in damage types, cutting, impaling, crushing, four different kinds of piercing, burning...
But it doesn't extend to tables. :D

User avatar
metatheurgist
Dragon
Posts: 363
Joined: Mon Oct 26, 2009 5:51 am

Re: strfind() - doesn't like my regexes

Post by metatheurgist »

jfrazierjr wrote:There were some 30-50 or more results on multiple tables depending on if you were using spell(seperated tables for fire, cold, electric, etc), piercing, bludgeoning, or slashing weapons. Of course, it was all super descriptive. Way to super detailed for me.... However, this would be an incredible system to utilize in maptool(if players are willing to take the chance of one hit killing them or permently disabling a body part!!!!) with the various data lookup tools we have... it could be done in seconds and never a player looking at a table other than loading it in the first time data dump.
Nah, those tables look fun (probably to 12 years olds) but in practice they suck. By the time you've got your 30th death from ruptured kidneys it's just boring. Ran Deathwatch recently and they have similar though smaller tables for crits. In one long fight I had an opponent's eye scooped out of his head 12 times. At the end I just said "You find a disturbing amount of eyes littered about the floor". Helps that it's a game with chaos mutations. :wink:

Post Reply

Return to “Macros”