filter_wml vs formula
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.
filter_wml vs formula
Hi,
I seem to be having some problems with the given example in the wiki.
https://wiki.wesnoth.org/FilterWML/Exam ... #this_unit
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]
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?)
Any ideas of what is going on with the filter_wml?
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'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]
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]
Re: filter_wml vs formula
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.
Re: filter_wml vs formula
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]
Re: filter_wml vs formula
ah yes that's what i meant, no reason so use filter_wml here.vghetto wrote: ↑July 7th, 2020, 1:03 amHey 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]
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.
- Celtic_Minstrel
- Developer
- Posts: 2166
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: filter_wml vs formula
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]
.