[or] combined with [and]

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

[or] combined with [and]

Post by SlowThinker »

I have a question concerning filters and conditions:

Code: Select all

conditionA # any value
[and] 
	conditionB # false
[/and] 
[or]
	conditionC # true
[/or]
According the wiki the result of the code above should be simutaneously true and false.

So how are combined [and], [or] evaluated? I can imagine
  1. ((((A and B) or C) and D) or E)
    or
  2. (A and (B or (C and (D or E))))
  3. or ...?
ConditionalActionsWML doesn't help, but the information related to [or] here: StandardLocationFilter mentions "previous filters", and so 1. above might be the answer?
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
User avatar
Pentarctagon
Project Manager
Posts: 5730
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: [or] combined with [and]

Post by Pentarctagon »

Its pretty straight forward. The follow condition:

Code: Select all

[if]
[variable]
name=a
equals=1
[/variable]
[variable]
name=b
equals=2
[/variable]
[or]
[variable]
name=c
equals=3
[/variable]
[variable]
name=d
equals=4
[/variable]
[/or]
[or]
[variable]
name=e
equals=5
[/variable]
[/or]
[then]
...
would evaluate as true and execute the code inside [then] if -
a=1 and b=2
or
c=3 and d=4
or
e=5

So a, b, c, d, and e could all be equal to 5, and it would still evaluate as true.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: [or] combined with [and]

Post by SlowThinker »

My question is what happens is both [and], [or] are used:
I replaced 'or' by 'AND':

a=1 and b=2
AND
c=3 and d=4
or
e=5
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [or] combined with [and]

Post by Sapient »

Code: Select all

  [filter]
     {ANYTHING}
      [or]
        {X}
      [/or]
  [/filter]
true if {X} is true or if {ANYTHING} is true...

where {ANYTHING} may contain [and], etc.

However, the documentation on the wiki is wrong, in that it is still possible for the filter to evaluate to false even after one [or] filter evaluates to true. For example:

Code: Select all

  [filter]
     {ANYTHING}
      [or]
        {X}
      [/or]
      [not]
        # always fail here
      [/not]
  [/filter]
will always be false
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: [or] combined with [and]

Post by SlowThinker »

Thank you.
I expect [and] works similar way like [or] (no need to answer if this is true).
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [or] combined with [and]

Post by Sapient »

FYI, I updated the wiki documentation for ConditionalActionsWML
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: [or] combined with [and]

Post by SlowThinker »

1. I like your explanation in this thread much than the one you added to wiki.

2. I am confused. I see you edited [or], but why you didn't edit [and] too?
Now the code in the very beginning of this thread
  • should be false, because of
    wiki wrote:[and]
    A condition which must evaluate to true in addition to any others.
  • and simultaneously it should be true, because of
    wiki wrote:[or]
    This condition, if true, allows the containing tag to also evaluate as true despite any false conditions preceding this one and without regard to any false conditions in the immediate contents of the containing tag. In other words, if any one [or] tag evaluates as true (and no false [and] or [not] tags come after it) then the action will take place.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [or] combined with [and]

Post by Sapient »

Yes, the documentation still has some room for improvement. The goal is to be precise, concise, and also easily comprehensible. I will edit it again when I think of a better phrasing (or someone else can edit it, if they care to try).
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: [or] combined with [and]

Post by SlowThinker »

I can try something (but then somebody will have to 'translate' it in a better english).
But I have a question: is the list of Meta Condition Tags evaluated from the first one or from the last one? (And is the evaluation strict or non-strict?)
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [or] combined with [and]

Post by Sapient »

Ok, after posting a second revision, I think the explanation of meta-conditions is good enough to leave it alone for now.

While I would hope that most people understand "top-to-bottom" without further explanation, for the sake of completeness I added a section which explains exactly what is meant by top-to-bottom evaluation order.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: [or] combined with [and]

Post by SlowThinker »

  • I still see [and] to be confusing
  • I think it is confusing that [or], [and], [not] are explained a different way.
Therefore this is my suggestion (but I am not sure about english):
[or]
A condition which is joined with the summary of all previous conditions by logical "OR". Therefore, when false, it has no effect, but when true, it turns the effect of all previous conditions to true.

[and]
A condition which is joined with the summary of all previous conditions by logical "AND". Therefore, when true, it has no effect, but when false, it turns the effect of all previous conditions to false.

[not]
A condition which is joined with the summary of all previous conditions by logical "AND NOT". Therefore, when false, it has no effect, but when true, it turns the effect of all previous conditions to false.
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
Post Reply