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.
Feedback thread 'Examples - How to use Filter' wiki page
Inspired by this question: [filter_location] problem
Using filter is for me (and for many others I guess) the hardest thing in WML.
Finally I found myself a solution for my question I mentioned above, but for the price of spending hours and hours trying & fail, trying out every possible combination.
I really wish there were much more examples how [filter] works, and how to use [filter] in the Wiki, or some site that explains filtering here in the forums.
It would be great if someone who really understands how filtering works can start such a site, or a Wiki page.
EDIT: You find a very good documentation written by Pyrophorus about using filters here: How to use filters
EDIT 2: 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.
Using filter is for me (and for many others I guess) the hardest thing in WML.
Finally I found myself a solution for my question I mentioned above, but for the price of spending hours and hours trying & fail, trying out every possible combination.
I really wish there were much more examples how [filter] works, and how to use [filter] in the Wiki, or some site that explains filtering here in the forums.
It would be great if someone who really understands how filtering works can start such a site, or a Wiki page.
EDIT: You find a very good documentation written by Pyrophorus about using filters here: How to use filters
EDIT 2: 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.
Last edited by Adamant14 on June 23rd, 2013, 8:56 pm, edited 8 times in total.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Re: Examples how to use [filter]?
I personally find the desciption of filtering on the wiki sufficient. When I was making a scenario with rising lava, I just looked at the wiki, put together a some filters and made it store all locations adjacent to areas already covered by lava, except cave walls, and it worked. When I needed to make a weapon special that hurts units in this pattern, damaging three units on the line behind the target and also units next to this line, I looked at the wiki, assembled it, and it worked.
If that matters, there is a good example of complicated terrain filtering the the final battle of episode 2 of After the Storm.
If that matters, there is a good example of complicated terrain filtering the the final battle of episode 2 of After the Storm.
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Examples how to use [filter]?
Yeah, filters can be rather unwieldy at times. Simple ones are alright, but I generally try to avoid using them whenever possible.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Examples how to use [filter]?
Bad idea. I regularly get confused by SLFs which include a radius=, but filters are usually rather fast; it is known they're used a lot and developers try to make their implementations faster. Better than variable bashing. Filters also can pack a lot of logic into pretty few wml code. Well, the latter point is much more important, probably.Pentarctagon wrote:I generally try to avoid using them whenever possible.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Examples how to use [filter]?
As I understand it, the general rule is that you don't usually need to worry about the efficiency of WML; so if I have a choice between poking at a filter for possibly hours and then possibly having it still not work or writing an if/then statement or two in 5 minutes that I can understand exactly how it works just by reading it I'm rarely, if ever, going to go with the filter.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: Examples how to use [filter]?
Exactly why is this in Off-Topic? Moving to WML Workshop.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Re: Examples how to use [filter]?
Location filters are a declarative relational programming language, which requires a sort of reverse way of thinking. Instead of telling the game how to go and get the locations (imperative), you must tell it instead how the locations are related (declarative), then it will go get them in the most efficient manner.
It may help to study some Set Theory and begin to think of locations in terms of sets. But there are a substantial number of programmers who find it very difficult to think like this. Some people are great at languages like C# but fail to write good SQL no matter how hard they try, even after years of practice.
Another obstacle to understanding is failing to read the documentation. There is a very common mistake with the use of radius, because it is a bit counter-intuitive. But if you read the ReferenceWML section on location filtering (SLF), it explains exactly how the radius works. (And there is a good reason why it works this way.)
It may help to study some Set Theory and begin to think of locations in terms of sets. But there are a substantial number of programmers who find it very difficult to think like this. Some people are great at languages like C# but fail to write good SQL no matter how hard they try, even after years of practice.
Another obstacle to understanding is failing to read the documentation. There is a very common mistake with the use of radius, because it is a bit counter-intuitive. But if you read the ReferenceWML section on location filtering (SLF), it explains exactly how the radius works. (And there is a good reason why it works this way.)
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: Examples how to use [filter]?
My origin intention why I started this topic, was the idea to have a site where UMC autors can find reference examples of applied filters.
Examples, which are good described for guys like me, who have no idea how filtering works.
An example is always better to understand as the best wiki entry.
Examples, which are good described for guys like me, who have no idea how filtering works.
An example is always better to understand as the best wiki entry.
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 !
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.
Updated version: Comments and corrections are welcomed.
Have fun !
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.
Updated version: Comments and corrections are welcomed.
Have fun !
Last edited by pyrophorus on May 26th, 2013, 8:51 am, edited 1 time in total.
HowTos: WML filtering, WML variables
Re: Examples how to use [filter]?
Wow, thanks for going to the trouble of typing this up. I found it very interesting and detailed. There were a few errors, mostly insignificant. But here were a few problems that stood out:
* The game has no concept of order in which attributes are written, so the example at the top of page 7 is incorrect. However what it says next is correct that the order of attribute evaluation can be forced through [and], which is a clever idea.
* On page 15, the second example (where it says "since the x,y keys are defined in [filter] too, it can be") there is a missing [filter] tag
* Your teleport example at the bottom of page 17 seemed to be overly complicated to demonstrate the simple point you were trying to make. I felt that it detracted more than it helped to understand anything.
* The game has no concept of order in which attributes are written, so the example at the top of page 7 is incorrect. However what it says next is correct that the order of attribute evaluation can be forced through [and], which is a clever idea.
* On page 15, the second example (where it says "since the x,y keys are defined in [filter] too, it can be") there is a missing [filter] tag
* Your teleport example at the bottom of page 17 seemed to be overly complicated to demonstrate the simple point you were trying to make. I felt that it detracted more than it helped to understand anything.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: Examples how to use [filter]?
Thanks for reading the paper !
I will add something to tell order is undefined, except when using operators tags. Anyway, I don't want to dig too deep in this topic, because it would probably confuse my readers. Only give some hints.
Thanks for your feedback !
Friendly,
Yes, I should have fetch the C++ code to clarify this point, and I didn't out of lazyness. Actually, I hoped some dev would do that for me.Sapient wrote:Wow, thanks for going to the trouble of typing this up. I found it very interesting and detailed. There were a few errors, mostly insignificant. But here were a few problems that stood out:
* The game has no concept of order in which attributes are written, so the example at the top of page 7 is incorrect. However what it says next is correct that the order of attribute evaluation can be forced through [and], which is a clever idea.
I will add something to tell order is undefined, except when using operators tags. Anyway, I don't want to dig too deep in this topic, because it would probably confuse my readers. Only give some hints.
??? In this code ? I can't see the errorSapient wrote: * On page 15, the second example (where it says "since the x,y keys are defined in [filter] too, it can be") there is a missing [filter] tag
Spoiler:
Hmmm... Which simple point ? Do you mean I should explain filter_location with a simpler example ? There, I am aware to show how filters can be nested, even very deep, more than illustrating the filter_location filter. I agree the example is very complex (and useless in a scenario), but since we built it step by step, I hope readers will catch the way to design complex filters.Sapient wrote: * Your teleport example at the bottom of page 17 seemed to be overly complicated to demonstrate the simple point you were trying to make. I felt that it detracted more than it helped to understand anything.
Thanks for your feedback !
Friendly,
HowTos: WML filtering, WML variables
Re: Examples how to use [filter]?
I've only glanced over it briefly so far, but it looks like a very useful guide, thanks. So I'm sorry my only comment is a possible error (page 19):
I'm not the best at WML, so maybe I'm missing something. But it seems to me like you assume that side alliances will never change in a scenario. The first filter won't always return the same result if side 2's alliances switch at different times in the scenario, right?Here, we can mark the is_enemy key is redundant because sides already define if the units areCode: Select all
[filter] side=1 [filter_adjacent] side=2 is_enemy=yes [/filter_adjacent] [/filter]
enemy or not. So, if side 1 and 2 are allied, the filter will always return an empty set. If they
are not, it will always match, so the is_enemy criterion is useless. This filter:
will always return exactly the same result.Code: Select all
[filter] side=1 [filter_adjacent] side=2 [/filter_adjacent] [/filter]
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: Examples how to use [filter]?
Thanks for reading and reporting.
You're right. The example is not good, and I'll try to find another one or put a side note.
Friendly,
You're right. The example is not good, and I'll try to find another one or put a side note.
Friendly,
HowTos: WML filtering, WML variables
Re: Examples how to use [filter]?
I have read the article, and must admit that nowhere else I have found any WML related matter so lucidly explained. I wish I had come across something like this 2 years ago, when I was struggling to find the head and tail of WML! Kudos to Pyrophorus and Adamant14 for giving their valuable time in writing this.
Current projects:
Rebellion in the North,Legend of Far North,Birth of a Lich,
Doreldos: Fight to Liberty
Rebellion in the North,Legend of Far North,Birth of a Lich,
Doreldos: Fight to Liberty
Re: Examples how to use [filter]?
Oh yes.chak_abhi wrote:I have read the article, and must admit that nowhere else I have found any WML related matter so lucidly explained. I wish I had come across something like this 2 years ago, when I was struggling to find the head and tail of WML!
I was longing for such a site since I struggle with WML.
Having such a site earlier, would have saved me a lot of time.
Don't thank me.chak_abhi wrote: Kudos to Pyrophorus and Adamant14 for giving their valuable time in writing this.
Pyrophorus is the one who deserves the honour.
He was the one who wrote these pages;
he knows more about WML than I ever will.
Thank you Pyrophorus.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR