Create account / Log in

Comparing properties

Talk about module design ideas and techniques.

Moderators: Tim M, uckelman

Comparing properties

Postby barbanera » January 23rd, 2012, 5:00 pm

Is there a way to do something like the following (for example in a Trigger property check):

Type = Infantry && (Status = dead || Defense < 3)

At the moment (Vassal 3.1.18) it doesn't seem to work, at least with that syntax. Regular expressions won't help, either, I think.

I can get around this problem by splitting it in two different triggers, or using a trigger and a combination of restrict commands etc.. but it seems a waste of keystrokes and/or traits.
barbanera
 
Posts: 377
Joined: January 12th, 2012, 2:27 pm

Re: Comparing properties

Postby Tim M » January 23rd, 2012, 6:11 pm

barbanera wrote:Is there a way to do something like the following (for example in a Trigger property check):

Type = Infantry && (Status = dead || Defense < 3)

At the moment (Vassal 3.1.18) it doesn't seem to work, at least with that syntax. Regular expressions won't help, either, I think.

I can get around this problem by splitting it in two different triggers, or using a trigger and a combination of restrict commands etc.. but it seems a waste of keystrokes and/or traits.


This is only way how at moment:

Type = Infantry && Status = dead || Type = Infantry && Defense < 3
Tim,
Vassal Uber Geek/Guru

Problems? post your OS, Physical Mem, version of Vassal and Java plus the Module in question.
No developer can help with out that info, thx!
User avatar
Tim M
 
Posts: 1777
Joined: December 8th, 2007, 12:22 pm
Location: Earth

Re: Comparing properties

Postby barbanera » January 23rd, 2012, 7:49 pm

Thanks for your help.

Can I infer from your example that every || divides properties matches in independently evalued blocks?

Thas is: xxxx && yyyyy && zzzz || 1111 && 2222 || aaaa

is equivalent to (xxxx && yyyy && zzz) || (1111 && 2222) || aaaa ?
barbanera
 
Posts: 377
Joined: January 12th, 2012, 2:27 pm

Re: Comparing properties

Postby Tim M » January 23rd, 2012, 9:08 pm

mmm yes and no, all depends on how used in the expression

In the original case you gave above and your examples it is a dividing OR but it (should) be possible to make it a substituting OR

example:

Type = Infantry && Status = Dead||Wounded

generally in that case though I go with the single pipe which works also
Tim,
Vassal Uber Geek/Guru

Problems? post your OS, Physical Mem, version of Vassal and Java plus the Module in question.
No developer can help with out that info, thx!
User avatar
Tim M
 
Posts: 1777
Joined: December 8th, 2007, 12:22 pm
Location: Earth

Re: Comparing properties

Postby irishwulf » January 24th, 2012, 1:13 am

Is the order of operations published somewhere? Honestly, I have been splitting complex expressions into multiple triggers to be sure the order is explicit, but it would be handy to know how the expressions are actually evaluated.

-Seth
irishwulf
 
Posts: 243
Joined: December 17th, 2011, 4:29 am

Re: Comparing properties

Postby JustaBill » January 25th, 2012, 5:27 pm

The latest Designer Guide says, on page 15
A Property comparison using AND or OR may only use a single instance of AND or OR. Parentheses, brackets, and precedence
are not supported.

Is this incorrect?
JustaBill
 
Posts: 21
Joined: October 25th, 2011, 3:34 pm

Re: Comparing properties

Postby mycenae » January 25th, 2012, 5:32 pm

Based on Tim's earlier post, the first sentence appears to be incorrect, but not the second. See

viewtopic.php?f=6&t=3835&p=21971&hilit=precedence#p21971

I will fix the first sentence in the next version of the Guide.
mycenae
 
Posts: 392
Joined: May 16th, 2008, 6:41 pm

Re: Comparing properties

Postby JustaBill » January 27th, 2012, 3:36 am

I was able to verify in my own module that, indeed, we are not limited to a single logical comparison operator. However, I didn't test precedence. For the time being I assume everything is left-to-right, as if there are implicit parentheses like these:

((((value OP value) OP value) OP value) OP value)

But, again, I have not tested this assumption.
JustaBill
 
Posts: 21
Joined: October 25th, 2011, 3:34 pm

Re: Comparing properties

Postby irishwulf » January 27th, 2012, 6:13 pm

A quick look at the PropertiesPieceFilter class indicates that the way this is done in 3.1.18 is:
(1) Split the expression around ||
(2) Split each subexpression around &&
(3) Try to match each subexpression to an OPERAND COMPARATOR OPERAND pattern - succeed (!!) if unable to match this pattern (so, i.e., setting 'MyProp' to 'false', and entering 'MyProp' as the property match expression, will always succeed. For that matter, 'false' will always succeed)

This order, with OR operands at the highest level, is borne out in my own brief testing; so, for instance, the following will evaluate to true with MyProp = TRUE:
MyProp = FALSE && MyProp = FALSE || MyProp = TRUE

Cheers,
Seth
irishwulf
 
Posts: 243
Joined: December 17th, 2011, 4:29 am

Re: Comparing properties

Postby barbanera » January 28th, 2012, 12:45 pm

Therefore, basically you are saying that the answer to my question above is YES.
I can confirm I have noticed this is how things appear to be working, after the original reply by Tim M.


barbanera wrote:Thanks for your help.

Can I infer from your example that every || divides properties matches in independently evalued blocks?

Thas is: xxxx && yyyyy && zzzz || 1111 && 2222 || aaaa

is equivalent to (xxxx && yyyy && zzz) || (1111 && 2222) || aaaa ?


:)
barbanera
 
Posts: 377
Joined: January 12th, 2012, 2:27 pm


Return to Module Design

Who is online

Users browsing this forum: No registered users and 1 guest