Feedback thread 'Examples - How to use Filter' wiki page

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.
User avatar
Adamant14
Posts: 962
Joined: April 24th, 2010, 1:14 pm

Feedback thread 'Examples - How to use Filter' wiki page

Post by Adamant14 »

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. :roll:
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: :arrow: :arrow: :arrow: 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
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Examples how to use [filter]?

Post by Dugi »

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.
User avatar
Pentarctagon
Project Manager
Posts: 5496
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Examples how to use [filter]?

Post by Pentarctagon »

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
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Examples how to use [filter]?

Post by Anonymissimus »

Pentarctagon wrote:I generally try to avoid using them whenever possible.
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.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Pentarctagon
Project Manager
Posts: 5496
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Examples how to use [filter]?

Post by Pentarctagon »

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
User avatar
Iris
Site Administrator
Posts: 6796
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: Examples how to use [filter]?

Post by Iris »

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.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Examples how to use [filter]?

Post by Sapient »

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.)
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Adamant14
Posts: 962
Joined: April 24th, 2010, 1:14 pm

Re: Examples how to use [filter]?

Post by Adamant14 »

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. :P
An example is always better to understand as the best wiki entry. :hmm:
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Examples how to use [filter]?

Post by pyrophorus »

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:
WMLFiltering.pdf.zip
(64.8 KiB) Downloaded 626 times
Comments and corrections are welcomed.

Have fun !
Last edited by pyrophorus on May 26th, 2013, 8:51 am, edited 1 time in total.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Examples how to use [filter]?

Post by Sapient »

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.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Examples how to use [filter]?

Post by pyrophorus »

Thanks for reading the paper !
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.
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. :lol2:

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.
Sapient 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
??? In this code ? I can't see the error :roll:
Spoiler:
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.
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.

Thanks for your feedback !

Friendly,
H-Hour
Posts: 222
Joined: April 14th, 2010, 12:27 pm

Re: Examples how to use [filter]?

Post by H-Hour »

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):

Code: Select all

[filter]
	side=1
	[filter_adjacent]
		side=2
		is_enemy=yes
	[/filter_adjacent]
[/filter]
Here, we can mark the is_enemy key is redundant because sides already define if the units are
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:

Code: Select all

[filter]
	side=1
	[filter_adjacent]
		side=2
	[/filter_adjacent]
[/filter]
will always return exactly the same result.
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?
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Examples how to use [filter]?

Post by pyrophorus »

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,
chak_abhi
Posts: 347
Joined: June 24th, 2010, 3:37 pm

Re: Examples how to use [filter]?

Post by chak_abhi »

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! :P Kudos to Pyrophorus and Adamant14 for giving their valuable time in writing this. :)
User avatar
Adamant14
Posts: 962
Joined: April 24th, 2010, 1:14 pm

Re: Examples how to use [filter]?

Post by Adamant14 »

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!
Oh yes.
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. :)
chak_abhi wrote: :P Kudos to Pyrophorus and Adamant14 for giving their valuable time in writing this. :)
Don't thank me.
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
Post Reply