filter_wml vs formula

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
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

filter_wml vs formula

Post by vghetto »

Hi,

I seem to be having some problems with the given example in the wiki.
https://wiki.wesnoth.org/FilterWML/Exam ... #this_unit

Code: Select all

[filter]
    side=1
    [filter_wml]
        hitpoints=$this_unit.max_hitpoints
    [/filter_wml]
[/filter]
I don't know what is going on, but when used inside a mirco_ai filter it doesn't seem to work as expected.
I'm looking for units that are not at full health, so I inverted the filter_wml with a [not]

Code: Select all

[filter]
    side=1
    [not]
        [filter_wml]
            hitpoints=$this_unit.max_hitpoints
        [/filter_wml]
    [/not]
[/filter]
But for some reason, that didn't work. Regardless of whether the unit was injured or not, that filter selected all units.

Without the [not], none of the units got selected! injured or at max health, nada! It's as if the value of $this_unit.max_hitpoints is undefined or something.

On the other hand, this seems work perfectly inside a micro_ai filter. (is the self redundant?)

Code: Select all

[filter]
    side=1
    formula="self.hitpoints < self.max_hitpoints"
[/filter]
Any ideas of what is going on with the filter_wml?
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: filter_wml vs formula

Post by gfgtdf »

it's quite possible that $this_unit doesn't work in certain contsts becasue the value is evaluates before the filter is evaluates. I just really reccomand to use formula here instead. Also even if you wants to use hitpoints=$this_unit.max_hitpoints you should put it into filter_wml no idea why the wiki example does that.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: filter_wml vs formula

Post by vghetto »

gfgtdf wrote: July 6th, 2020, 12:42 pm Also even if you wants to use hitpoints=$this_unit.max_hitpoints you should put it into filter_wml no idea why the wiki example does that.
Hey thanks for the response, I'm not sure what you mean here, could you rephrase please? the wiki example does use filter_wml. Are you saying that filter_wml wasn't necessary and the following could have worked?

Code: Select all

[filter]
    side=1
    hitpoints=$this_unit.max_hitpoints
[/filter]
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: filter_wml vs formula

Post by gfgtdf »

vghetto wrote: July 7th, 2020, 1:03 am
gfgtdf wrote: July 6th, 2020, 12:42 pm Also even if you wants to use hitpoints=$this_unit.max_hitpoints you should put it into filter_wml no idea why the wiki example does that.
Hey thanks for the response, I'm not sure what you mean here, could you rephrase please? the wiki example does use filter_wml. Are you saying that filter_wml wasn't necessary and the following could have worked?

Code: Select all

[filter]
    side=1
    hitpoints=$this_unit.max_hitpoints
[/filter]
ah yes that's what i meant, no reason so use filter_wml here.

But i don't think that that's why your code doesn't work, its more likely that $this_unit works a bit different inside micro_ai. So i still just recomend to use formula
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: filter_wml vs formula

Post by Celtic_Minstrel »

The main reason to use [filter_wml] is if you want to filter on the contents of unit variables. I think even that can be handled via a formula, but it's probably more convenient and readable to use [filter_wml][variables].
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply