Feedback thread 'Examples - How to use Filter' wiki page
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.
Re: Examples how to use [filter]?
wow - this is really a great guide. any chance you could move it to the wiki?pyrophorus wrote:With Adamant, we went a little further and here is the result: a short howto trying to make easier filters understanding and use, and we hope it will help.
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: Examples how to use [filter]?
I have read the text very quickly, and so I might miss something, but ...
------------------------------
I think you should explain how 'parentheses are added' to the code when it is parsed, because filters are not always intuitive in this aspect.
examples:
is processed like
is processed like
-------------------------------
These two tags are identical because the internal representation of WML tags in lua doesn't distinguish any order among WML attributes (this is true in general, not only in filters).
------------------------------
I think you should explain how 'parentheses are added' to the code when it is parsed, because filters are not always intuitive in this aspect.
examples:
[and]A[/and] [or]B[/or] [and]C[/and] [not]D[/not] ...
is processed like
(((((Universum and A) or B) and C) and_not D) ... )
[SLF]x= y= terrain= radius=xyz [and]...[/and][/SLF]
is processed like
function_radius=xyz([SLF]x= y= terrain= [and]...[/and][/SLF])
-------------------------------
Code: Select all
[filter]
race=orc
x,y=16,22
[/filter]
[filter]
x,y=16,22
race=orc
[/filter]
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
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
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: Examples how to use [filter]?
Hi !
Thanks to everyone for the feedback !
(A) or (B) and (C) (not D)
What does this means ? It can be read as:
( A or B) and (C and (not D)) -> [and] A [or]B[/or] [/and] [and] C [not]D[/not] [/and]
or:
A or ( B and C and (not D)) -> A [or] B C [not] D [/not] [/or]
or even otherwise. These "translations" are unambiguous when the original writing is not. Of course, filter execution will be only one of those because there are operators precedence rules. But writing filters like this is IMO the best way to write code that will not work as expected and to spend hours in trial and error process. If it's clear in one's head (and in natural writing) it will be too in the code. If not... well...
The point is not important, but as I said, it can be useful to use logical operators to enforce an evaluation order in some special cases (when using filter_wml particularly).
Friendly,
Thanks to everyone for the feedback !
Not only... I wrote, but Adamant provided me with examples and questions, read the drafts, and IMO really oriented the work and deserves to sign it with me.Adamant14 wrote:Don't thank me.
Pyrophorus is the one who deserves the honour.
He was the one who wrote these pages;
Well, maybe later. But I'm rather reluctant to do that because to me, wiki syntax sucks. But if anyone wants to do the job, be my guestMax wrote:wow - this is really a great guide. any chance you could move it to the wiki?
I'm not writing a reference manual here, and your example is exactly what I would strongly discourage readers to do. If you translate it in natural speech; it would become:SlowThinker wrote:I think you should explain how 'parentheses are added' to the code when it is parsed, because filters are not always intuitive in this aspect.
examples:
[and]A[/and] [or]B[/or] [and]C[/and] [not]D[/not] ...
(A) or (B) and (C) (not D)
What does this means ? It can be read as:
( A or B) and (C and (not D)) -> [and] A [or]B[/or] [/and] [and] C [not]D[/not] [/and]
or:
A or ( B and C and (not D)) -> A [or] B C [not] D [/not] [/or]
or even otherwise. These "translations" are unambiguous when the original writing is not. Of course, filter execution will be only one of those because there are operators precedence rules. But writing filters like this is IMO the best way to write code that will not work as expected and to spend hours in trial and error process. If it's clear in one's head (and in natural writing) it will be too in the code. If not... well...
The point was already quoted by Sapient. My purpose is more to illustrate the idea of "more restrictive criterion first" than to give a description of how things works internally (I said twice it was not my purpose). Anyway, since programs are deterministic, here too, one could explain exactly in which order criteria are evaluated: "lua doesn't distinguish any order among WML attributes" is of course an approximation of something maybe very complex and in any way far beyond the scope of our paper.SlowThinker wrote: These two tags are identical because the internal representation of WML tags in lua doesn't distinguish any order among WML attributes (this is true in general, not only in filters).
The point is not important, but as I said, it can be useful to use logical operators to enforce an evaluation order in some special cases (when using filter_wml particularly).
Friendly,
HowTos: WML filtering, WML variables
-
- Posts: 876
- Joined: November 28th, 2008, 6:18 pm
Re: Examples how to use [filter]?
There are no operators precedence rules in filters. Multiple operator tags (and similarly multiple Meta-Condition Tags) are processed the way I explained above:pyrophorus wrote:These "translations" are unambiguous when the original writing is not. Of course, filter execution will be only one of those because there are operators precedence rules.
(((((Universum and A) or B) and C) and_not D) ... )
Maybe you are confused by wiki, which is not very clear (see this post: http://forums.wesnoth.org/viewtopic.php ... 23#p531123 )
I believe "Wesnoth cannot distinguish any order among WML attributes" is a principle that would help WML users to understand things.pyrophorus wrote:"lua doesn't distinguish any order among WML attributes" is of course an approximation of something maybe very complex and in any way far beyond the scope of our paper
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
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
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: Examples how to use [filter]?
One again (and the last one), my goal is to help WML users who are not easy with progamming and formal descriptions. How could they read this ?
For myself, I'm not interested in theoretical discussion about WML because this language is an ugly hack. Not because it was badly designed. Because it was intended to follow the KISS principle as far as possible. The result is powerful and yet rather easy to use. But because it's a tradeof between consistency and simplicity, it has black patches and traps. My opinion is it's better to shun them when you don't need to dig into.
Friendly,
I'm not saying you're wrong. I'm saying these "explanations" look contradictory and so explain nothing and confuse readers. More of it, my readers are not interested in knowing exactly how WML works: they want to create filters which work as they expect. And if one works as I suggest, grouping conditions and creating blocks with [and] tags, using temporary variables to reduce complexity, they will get what they want.SlowThinker wrote:(((((Universum and A) or B) and C) and_not D) ... )
...
"Wesnoth cannot distinguish any order among WML attributes"[/i] is a principle that would help WML users to understand things.
For myself, I'm not interested in theoretical discussion about WML because this language is an ugly hack. Not because it was badly designed. Because it was intended to follow the KISS principle as far as possible. The result is powerful and yet rather easy to use. But because it's a tradeof between consistency and simplicity, it has black patches and traps. My opinion is it's better to shun them when you don't need to dig into.
Friendly,
HowTos: WML filtering, WML variables
Re: Examples how to use [filter]?
I second every single word.
Mind, this page is written for guys like me.
WML is the only computer language I ever learned,
and I think I am not the only one who only knows WML.
And this page is made for us.
There is the Wiki, and the Wiki is great, and no one wants to replace the Wiki,
this page is more a extension for the Wiki.
Pyrophorus explains all those things about filter's in a very clear and easy readable way.
In my opinion he made a very good job.
Thank you Pyrophorus.
Mind, this page is written for guys like me.
WML is the only computer language I ever learned,
and I think I am not the only one who only knows WML.
And this page is made for us.
There is the Wiki, and the Wiki is great, and no one wants to replace the Wiki,
this page is more a extension for the Wiki.
Pyrophorus explains all those things about filter's in a very clear and easy readable way.
In my opinion he made a very good job.
Thank you Pyrophorus.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: Examples how to use [filter]?
Hi !
I updated the HowTo, taking in account the observations given here by the readers.
I tried to clear the order problem and to give more clear hints to avoid pitfalls.
Hope it is better now.
Friendly,
I updated the HowTo, taking in account the observations given here by the readers.
I tried to clear the order problem and to give more clear hints to avoid pitfalls.
Hope it is better now.
Friendly,
HowTos: WML filtering, WML variables
Re: Examples how to use [filter]?
Examples how to use filters is now also available as a wiki page.
If you have any comments or suggestions, feel free to write it here in this thread.
If you have any comments or suggestions, feel free to write it here in this thread.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR