More filter examples

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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: More filter examples

Postby Sapient » September 1st, 2017, 3:50 pm

enclave wrote:radius comes even after all "and"s if not wrapped into an [and] himself?


Yes. The wiki says it too, although it gets often overlooked:

Note: [and],[or],and [not] extra location filters are considered after everything else in the containing filter (except radius, which is considered last in 1.3.8 and greater); they are then processed in the order encountered.
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
Sapient
Developer
 
Posts: 4368
Joined: November 26th, 2005, 7:41 am

Re: More filter examples

Postby enclave » September 1st, 2017, 6:47 pm

Sapient wrote:Yes. The wiki says it too, although it gets often overlooked:

that explains it all, thanks..!
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: More filter examples

Postby enclave » September 1st, 2017, 8:42 pm

7) lua wesnoth.get_locations with "not" in filter
local ns_test_locations = wesnoth.get_locations { {"not", { terrain = "W*,W*^*,Xv,_off^_usr" } }}
This will store all hexes of map which dont have water or not impassable (in this example I test only these 2: "Xv,_off^_usr", but in reality there is much more impassable types). So the key is to put double brackets before "not" if there is no filter previously... for example if there was filter it would "probably" look like so: local ns_test_locations = wesnoth.get_locations { x=10,y=10 {"not", { terrain = "W*,W*^*,Xv,_off^_usr" } }} -> so no double brackets...

7) lua wesnoth.get_locations with "not" and "and" in filter
Code: Select all
local my_location_container = wesnoth.get_locations { {"not", { terrain = "W*,W*^*,Xv,_off^_usr" }}, {"and", { x=1, y=1, radius=4 }}}

This is working equivalent of following WML filter code:
Code: Select all
[store_locations]
   [not]
      terrain=W*,W*^*,Xv,_off^_usr
   [/not]
   [and]
       x,y=1,1
       radius=4     
   [/and]
   variable=my_location_container
[/store_locations]
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Previous

Return to WML Workshop

Who is online

Users browsing this forum: No registered users and 5 guests