Filterning terrains without overlay doesn't work as intended?

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
BajMic
Posts: 44
Joined: January 24th, 2023, 1:22 am

Filterning terrains without overlay doesn't work as intended?

Post by BajMic »

According to the wiki:
The overlay (including the preceding ^) is optional; if omitted, only terrains without overlays can be matched.
So I tried:

Code: Select all

terrain=*
All terrains got matched.

Next, I tried:

Code: Select all

[not]
	terrain=*^*
[/not]
No terrain got matched. Is there a way of implicitly filtering out terrains with no overlays?
User avatar
Ravana
Forum Moderator
Posts: 3018
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filterning terrains without overlay doesn't work as intended?

Post by Ravana »

Confirmed. Seems you have to filter by terrain code.

Code: Select all

$ #wesnoth.get_locations{formula="1-contains_string(id, '^')"}
636
$ #wesnoth.get_locations{formula="contains_string(id, '^')"}
234
$ #wesnoth.get_locations{}
870
User avatar
Spannerbag
Posts: 537
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Filterning terrains without overlay doesn't work as intended?

Post by Spannerbag »

Edited out because of Ravana's far superior method below :)
FWIW you can replicate Ravana's logic in WML, I've done some brief testing and here's what happened on v1.16.8...

Cheers!
-- Spannerbag
Last edited by Spannerbag on June 24th, 2023, 3:19 pm, edited 1 time in total.
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Ravana
Forum Moderator
Posts: 3018
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filterning terrains without overlay doesn't work as intended?

Post by Ravana »

You dont need such tricks, standard location filter is same logic no matter if you call it from wml or Lua.
So formula="1-contains_string(id, '^')" instead of terrain=
User avatar
Spannerbag
Posts: 537
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Filterning terrains without overlay doesn't work as intended?

Post by Spannerbag »

Ravana wrote: June 24th, 2023, 2:27 pm You dont need such tricks, standard location filter is same logic no matter if you call it from wml or Lua.
So formula="1-contains_string(id, '^')" instead of terrain=
Ah, cool. The code below worked first time :)

Code: Select all

    [store_locations]
      terrain=*^*
      variable=terrain_all
      include_borders=no
    [/store_locations]
    [store_locations]
      formula="contains_string(id, '^')"
      variable=terrain_with_overlays
      include_borders=no
    [/store_locations]
    [store_locations]
      formula="1 - contains_string(id, '^')"
      variable=terrain_without_overlays
      include_borders=no
    [/store_locations]
Handy to know, thanks.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Filterning terrains without overlay doesn't work as intended?

Post by Celtic_Minstrel »

Note: I recommend using not instead of 1 - in that formula. It has the same effect but gets the intended meaning across better.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply