Create account / Log in

Can anyone explain this Global Property=~"A|B|B" bug?

Talk about module design ideas and techniques.

Moderators: uckelman, Tim M

Can anyone explain this Global Property=~"A|B|B" bug?

Postby Benkyo » April 20th, 2021, 8:17 am

I just spent hours, literally hours banging my head against the wall trying to debug a fairly simple problem:

Some pieces set a Global Property "Suit" to whatever their Marker value for "SetSuit" is (Hearth favor, Nomad favor, Beast favor, Arcane favor, Discord favor, or Order favor) when moved to a subset of Zones that have the Global Property.

A global key command tells all "Favor" pieces with a matching expression Suit=~"Hearth favor|Nomad favor|Beast favor|Arcane favor|Discord favor|Order favor" to do a thing.

Every Favor piece in an appropriate zone did the thing, except Favor pieces in zones with "Order favor" as the Suit.

I debugged for hours, going round in circles checking and rechecking. Eventually I tried changing the matching expression to Suit=~"Hearth favor|Nomad favor|Beast favor|Arcane favor|Discord favor|Order favor|Order favor" or in other words I just added an additional Order favor to the possible matches.

As soon as I did this, the global key command worked on every target Favor piece as intended.

Rechecking, reverting the matching expression to Suit=~"Hearth favor|Nomad favor|Beast favor|Arcane favor|Discord favor|Order favor" and again the global key commend stops working for Favor in zones with "Order favor" as the Suit value.

Can anyone explain this? It makes no sense to me. It is not a typo problem.
Benkyo
 
Posts: 381
Joined: March 13th, 2013, 11:02 pm

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby jrwatts » April 20th, 2021, 10:12 am

Looks like a bug in the regular expression parser to me. Out of curiosity, does Suit =~ "(Hearth|Nomad|Beast|Arcane|Discord|Order) favor" work?
jrwatts
 
Posts: 302
Joined: April 29th, 2020, 10:30 pm

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby Cattlesquat » April 20th, 2021, 3:12 pm

You could add another "bogus" suit on the end after Order favor, to transfer the bug to that "extra suit" and have all your other ones match? Oh right, it looks like that's what you did.

Or, what I often do is bypass the whole regular expression fussiness with: "Your|String|Of|Things".contains(Suit) which would work for your case.

Brian
User avatar
Cattlesquat
 
Posts: 1117
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby marktb1961 » April 20th, 2021, 3:15 pm

I’ve learned to do as Brian suggested and go with alternatives, so often regular expressions just don’t seem to work for me, despite careful checking.
Platform: Vassal 3.5.5, MacOS Big Sur on iMac (27", mid-2020)
User avatar
marktb1961
 
Posts: 564
Joined: October 4th, 2018, 2:36 pm
Location: Liverpool, England

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby Benkyo » April 20th, 2021, 9:34 pm

jrwatts wrote:Looks like a bug in the regular expression parser to me. Out of curiosity, does Suit =~ "(Hearth|Nomad|Beast|Arcane|Discord|Order) favor" work?

No, that doesn't work for *any* of the suits. Is that use of brackets correct? Or is this highlighting the fact that if it's the last expression bugging out, this rewriting makes all them the "last" expression?
Benkyo
 
Posts: 381
Joined: March 13th, 2013, 11:02 pm

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby Benkyo » April 20th, 2021, 9:44 pm

Cattlesquat wrote:You could add another "bogus" suit on the end after Order favor, to transfer the bug to that "extra suit" and have all your other ones match? Oh right, it looks like that's what you did.

Or, what I often do is bypass the whole regular expression fussiness with: "Your|String|Of|Things".contains(Suit) which would work for your case.

Brian

Thanks. This seems to work, but I don't understand why.

It also introduces a new bug, I suspect because the gkc condition now also affects other pieces resulting in a "Bad data" report where some pieces targeted by the gkc don't have a Suit value for a Send to destination. Maybe there are already in Zones that do not have a "Suit" value, but do correspond to "Your|String|Of|Things"? I assume I can fix that by giving those Zones a Suit value, but it does seem like a problem if .contains() regularly picks up stuff that the original regular expression is not supposed to.

It worries me that people are circumventing regular expressions as a matter of course. Is this a common source of very difficult to detect bugs? I use them all the time, and some of my modules are riddled with them.
Benkyo
 
Posts: 381
Joined: March 13th, 2013, 11:02 pm

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby Benkyo » April 20th, 2021, 9:56 pm

Oho, an update:

It seems that the problem might lie in how I was using the new gkc UI. Previously, my expressions were consistently wrapped in beanshell brackets {}

The new interface, with the expressions split into two either side of =~ in a dropdown menu, seems to make {} unnecessary, or at least, impossible to use with fast matching.

When I don't use fast matching, and write {Suit=~"Hearth favor|Nomad favor|Beast favor|Arcane favor|Discord favor|Order favor"}, the expression seems to work correctly, while Suit=~"Hearth favor|Nomad favor|Beast favor|Arcane favor|Discord favor|Order favor" does not (only for "Order"). Further, {Suit =~ "(Hearth|Nomad|Beast|Arcane|Discord|Order) favor"} also works only with the beanshell wrapper.
Benkyo
 
Posts: 381
Joined: March 13th, 2013, 11:02 pm

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby jrwatts » April 20th, 2021, 10:34 pm

So, Fast Match is actually using "old style" expressions, not Beanshell, then? Can you verify that, Brian?
jrwatts
 
Posts: 302
Joined: April 29th, 2020, 10:30 pm

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby Benkyo » April 20th, 2021, 10:45 pm

I should clarify: I meant that because the fast matching doesn't show a {} wrapper, I wasn't using them in the additional property field either. So, my fault. I haven't tried fast matching with the problem regular expression yet.
Benkyo
 
Posts: 381
Joined: March 13th, 2013, 11:02 pm

Re: Can anyone explain this Global Property=~"A|B|B" bug?

Postby marktb1961 » April 26th, 2021, 2:57 pm

This is working for me in a legacy Fast Match comparison

BasicName
=~
(Target|Retire|Stand)

It did not work until I enclosed the RegEx in the round brackets. I'm guessing that is a RegEx thing.

Re: Beanshell - Fast Match seems to strip out redundant {} and "", converting the expression back to a legacy one. On the other hand, with something like {"(Target|Retire|Stand)"+"|XXX"} the beanshell expression will persist and, presumably, work.
Platform: Vassal 3.5.5, MacOS Big Sur on iMac (27", mid-2020)
User avatar
marktb1961
 
Posts: 564
Joined: October 4th, 2018, 2:36 pm
Location: Liverpool, England


Return to Module Design

Who is online

Users browsing this forum: No registered users and 2 guests