[filter_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_formula]
[filter_formula]
seems extremely useful. It was added to WML recently, starting with BfW version 1.17.6. I've been tinkering with it, but haven't been able to accomplish anything. I think I need some functional examples using Wesnoth Formula Language.
If you know how to use
[filter_formula]
, please post some examples. For example, how would you use the filter to make an event fire at "dusk" every day?Any other examples using
[filter_formula]
would also be appreciated. The more the merrier. I'd especially like to see an example that uses event_data
.Thanks.
From the Wiki:
filter_formula (Version 1.17.6 and later only)
Similar to [filter_condition], but the condition is expressed in Wesnoth Formula Language. The formula has access to the following keys:
Event information:
event - the event name
event_id
event_data
loc, unit - primary event location
second_loc, second_unit - secondary event location
weapon, second_weapon
Gamestate information:
turn_number
time_of_day - the time of day ID
side_number - currently active side
sides - a list of all sides
units - a list of all units on the map
map - the entire game map as a two-dimensional array
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: [filter_formula]
Yikes. That is about 100 times more complicated than what I was doing. I was waaaay off.
The odds of me using
The odds of me using
[filter_formula]
in my BfW campaign just plummeted like a paralyzed falcon.Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: [filter_formula]
It isnt even [filter_formula], its key not tag.
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [filter_formula]
What are you talking about? There's nothing complicated there… though the two examples in the tests probably aren't very useful in practice.
Here's some examples that might actually have practical application (untested):
Code: Select all
[event]
# Event triggers if a heavily injured unit (<25% hp) moves to a keep
name=moveto
filter_formula="unit.hitpoints < 0.25 * unit.max_hitpoints and unit.terrain.keep"
# Or, an alternate way of writing the same thing
filter_formula="unit.hitpoints < 0.25 * unit.max_hitpoints and map.gamemap[loc].keep"
[/event]
[event]
# Event triggers if a falcon is attacked by a ranged weapon
name=attack
filter_formula="unit.race = 'falcon' and weapon.range = 'ranged'"
[/event]
[event]
# Event triggers if you move within 6 hexes of (7,8)
name=moveto
filter_formula="distance_between(loc, loc(7,8)) < 6"
[/event]
[event]
# Event triggers if a unit at full health is killed in one hit
name=attacker hits
filter_formula="second_unit.hitpoints = second_unit.max_hitpoints and event_data.damage_inflicted >= second_unit.max_hitpoints"
[/event]
Re: [filter_formula]
Thank you. Those examples were helpful.Celtic_Minstrel wrote: ↑December 1st, 2022, 2:36 am Here's some examples that might actually have practical application (untested):
I'll post that information below, for anybody else reading the thread.Celtic_Minstrel wrote: ↑December 1st, 2022, 2:36 am I also edited the wiki to add some explanation of what event_data is in general.
More examples ofFrom the Wiki:
event_data - additional information specific to the event, such as owner_side or damage_inflicted, or anything passed in [fire_event][data].
[filter_formula]
in action would be nice.I expect WML coders will be reading this thread for years, looking for examples.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: [filter_formula]
I tested the untested examples, and only 1 of the 3 examples worked.
2) Worked perfectly.
3) Test game crashed.
1) Didn't work but the test game was not interrupted.Celtic_Minstrel wrote: ↑December 1st, 2022, 2:36 am 1) filter_formula="unit.hitpoints < 0.25 * unit.max_hitpoints and unit.terrain.keep"
2) filter_formula="unit.hitpoints < 0.25 * unit.max_hitpoints and map.gamemap[loc].keep"
3) filter_formula="unit.race = 'falcon' and weapon.range = 'ranged'"
2) Worked perfectly.
3) Test game crashed.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [filter_formula]
1 of 3? It looks like you missed two of the examples I gave. That code box with the examples scrolls down.
I'd like more information on the crash.
I'd like more information on the crash.
Re: [filter_formula]
Oops. I had missed the other examples. Those are great examples. Would you post a few more? You're good at knowing the exact sort of filters scenario designers like to create.Celtic_Minstrel wrote: ↑December 1st, 2022, 1:29 pm 1 of 3? It looks like you missed two of the examples I gave. That code box with the examples scrolls down.
Okay. I'll show the code I used and tell the result. I re-tested everything just now, in case I had made a mistake yesterday (as it turns out, I did).
Code: Select all
[event]
# Event triggers if a heavily injured unit (<25% hp) moves to a keep
name=moveto
first_time_only=no
filter_formula="unit.hitpoints < 0.25 * unit.max_hitpoints and unit.terrain.keep"
[message]
speaker=unit
message="I am hurt."
[/message]
[/event]
This event didn't work yesterday, but it was my fault. I had left out the
first_time_only=no
while play-testing.Code: Select all
[event]
# Event triggers if a heavily injured unit (<25% hp) moves to a keep
name=moveto
first_time_only=no
filter_formula="unit.hitpoints < 0.25 * unit.max_hitpoints and map.gamemap[loc].keep"
[message]
speaker=unit
message="I am hurt."
[/message]
[/event]
Code: Select all
[event]
# Event triggers if a falcon is attacked by a ranged weapon
name=attack
first_time_only=no
filter_formula="unit.race = 'falcon' and weapon.range = 'ranged'"
[message]
speaker=MyLeader
message="The falcon was attacked by a ranged weapon!"
[/message]
[/event]
Code: Select all
[event]
# Event triggers if you move within 6 hexes of (7,8)
name=moveto
filter_formula="distance_between(loc, loc(7,8)) < 6"
[message]
speaker=unit
message="I moved within 6 hexes of hex (7,8)."
[/message]
[/event]
Code: Select all
[event]
# Event triggers if a unit at full health is killed in one hit
name=attacker hits
first_time_only=no
filter_formula="second_unit.hitpoints = second_unit.max_hitpoints and event_data.damage_inflicted >= second_unit.max_hitpoints"
[message]
speaker=unit
message="I killed the enemy in one hit!"
[/message]
[/event]
A Sea Serpent (side 1, attacker) has no choice but to kill a Ruffian (side 2) in a single hit. But the game crashed when the Sea Serpent attacked.
The Sea Serpent should have said, "I killed the enemy in one hit!"
I thought Mac OS finally got a crash log in this latest version of BfW, but when I clicked the "i" and looked in the logs folder, it was empty.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: [filter_formula]
It's kinda funny, after you ridiculed me for finding something complicated, that your subsequent code didn't work.Celtic_Minstrel wrote: ↑December 1st, 2022, 2:36 am What are you talking about? There's nothing complicated there…
Actually, it's reassuring to know that even the developers sometimes write code with critical errors.
I've tried several different things to get the falcon code you wrote to run properly, but nothing I tried helped.
I tried
attack.range
, for example, and second_unit.race = 'falcon'
plus some silly ideas that were long-shots.It would be awesome if your code worked. Do you know what's wrong with it? Does anybody know?
Code: Select all
[event] # DOES NOT WORK
# Event should trigger if a falcon is attacked by a ranged weapon
name=attack
first_time_only=no
filter_formula="unit.race = 'falcon' and weapon.range = 'ranged'"
[message]
speaker=MyLeader
message="The falcon was attacked by a ranged weapon!"
[/message]
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: [filter_formula]
I wouldnt count
filter_formula="turn_number = side_number"
and filter_formula="loc.x = loc.y"
complicated.- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: [filter_formula]
There must be a bug in the engine around this key. No error in WML code should crash the whole game, but several formulas apparently do, including any one using 'weapon'. There is an error message in the terminal:
I'm pretty sure C_M meant that formula to haveBattle for Wesnoth wrote: Caught general 'St12bad_weak_ptr' exception: bad_weak_ptr
second_unit.race='falcon'
, but it was marked "untested" after all. For the time being, you will have to take out the weapon clause if you want it to do something.Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: [filter_formula]
I was confused about
filter_formula
in the beginning of this thread, but it makes a lot more sense now, thanks to Celtic_Minstrel's examples. I like it when new code tags and keys and so forth get added to WML. Developers clearly want to make WML easier to use and more powerful, which is great. I probably should've waited until 1.17 was stable before I began experimenting, though. I've crashed Wesnoth a dozen different ways usingbeetlenaut wrote: ↑December 3rd, 2022, 2:41 am I'm pretty sure C_M meant that formula to havesecond_unit.race='falcon'
, but it was marked "untested" after all. For the time being, you will have to take out the weapon clause if you want it to do something.
filter_formula
.Huh? The green text in my signature went back to plain old black.
Anyhow...
filter_formula
is amazing, and I bet all of Celtic_Minstrel's code examples will work after 1.17 is stable. Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: [filter_formula]
Thats the purpose of dev versions. If you dont try the features, issues wont be found, and once it is already stable, it cant be changed since it would break compatibility.
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: [filter_formula]
This is why I didn't file a bug report on GitHub. As far as I can tell, using "weapon" doesn't ever work, but I don't know what other things you have tried that also crash the game. That may be useful information, so you should probably be the one to file that report. Assuming that you do, you should mention the error message about pointers that I posted. That would save the developers some time and make sure they were targeting the actual problem you are having.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide