[SOLVED] [filter_location] problem
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.
[SOLVED] [filter_location] problem
I still have problems with the [filter] tag.
I want to find a hex that can be terrain=Gg or terrain=Gs.
This hex should be vacant, and should be seven hexes away from id=Antar

I want to find a hex that can be terrain=Gg or terrain=Gs.
This hex should be vacant, and should be seven hexes away from id=Antar
Code: Select all
[store_locations]
[filter]
id=Antar
[/filter]
[and]
terrain=Gg,Gs
radius=7
[/and]
[not]
[filter]
[/filter]
[/not]
variable=found_loc
[/store_locations]
Last edited by Adamant14 on March 28th, 2013, 4:13 pm, edited 1 time in total.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Re: [filter_location] problem
I am not sure about this, but this might work.
Store Antar into a variable named Antar. Then do this:
Store Antar into a variable named Antar. Then do this:
Code: Select all
[store_locations]
x,y=$Antar.x,$Antar.y
radius=7
[and]
terrain=Gg,Gs
[/and]
variable=found_loc
[/store_locations]
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: [filter_location] problem
a shot in the dark:
Try putting the [not][filter] block into the [and] block.
It looks as if the [filter]id= and the [not][filter] blocks exclude *all* locations, the first one limits to the single hex with Antar, the second one excludes all hexes with a unit on them, including the hex with Antar.
If that doesn't work, more trial & error. I sometimes use {FOREACH and [label] afterwards as debug code in order to clearly make visible which locations got stored.
Alternatively, wait for Sapient to post in this thread.
EDIT
The radius=7 means "up to and including 7", not exactly 7 hexes.
Try putting the [not][filter] block into the [and] block.
It looks as if the [filter]id= and the [not][filter] blocks exclude *all* locations, the first one limits to the single hex with Antar, the second one excludes all hexes with a unit on them, including the hex with Antar.
If that doesn't work, more trial & error. I sometimes use {FOREACH and [label] afterwards as debug code in order to clearly make visible which locations got stored.
Alternatively, wait for Sapient to post in this thread.
EDIT
The radius=7 means "up to and including 7", not exactly 7 hexes.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: [filter_location] problem
Try this:
Code: Select all
[store_locations]
terrain=Gg,Gs
[and]
[filter]
id=Antar
[/filter]
radius=7
[/and]
[not]
[filter]
[/filter]
[/not]
[not]
[filter]
id=Antar
[/filter]
radius=6
[/not]
variable=found_loc
[/store_locations]
Re: [filter_location] problem
Thank you all for your answers, but sadly non of them did work for me.
Here is the code that works:I found this out by spending hours and hours trying out every possible combination.
I really wish there were much more examples how [filter] works, and how to use [filter] in the Wiki, or some site that explains filtering here in the forums.

Here is the code that works:
Code: Select all
[store_unit]
[filter]
id=Antar
[/filter]
variable=Antar_store
[/store_unit]
[unstore_unit]
variable=Antar_store
[/unstore_unit]
{VARIABLE search_radius 7}
[store_locations]
terrain=Re,Rd
[not]
[filter]
[/filter]
[/not]
[not]
[filter]
x,y=$Antar_store.x,$Antar_store.y
[/filter]
radius=6
[/not]
[and]
[filter]
x,y=$Antar_store.x,$Antar_store.y
[/filter]
radius=$search_radius
[/and]
variable=found_loc
[/store_locations]
[while]
[variable]
name=found_loc.length
less_than=1
[/variable]
[do]
# {DEBUG_MSG "Radius is $search_radius"}
{VARIABLE_OP search_radius add 1}
[store_locations]
terrain=Re,Rd
[not]
[filter]
[/filter]
[/not]
[not]
[filter]
x,y=$Antar_store.x,$Antar_store.y
[/filter]
radius=6
[/not]
[and]
[filter]
x,y=$Antar_store.x,$Antar_store.y
[/filter]
radius=$search_radius
[/and]
variable=found_loc
[/store_locations]
[/do]
[/while]
{CLEAR_VARIABLE Antar_store}
{CLEAR_VARIABLE found_loc}
{CLEAR_VARIABLE search_radius}

I really wish there were much more examples how [filter] works, and how to use [filter] in the Wiki, or some site that explains filtering here in the forums.
Last edited by 8680 on March 27th, 2013, 9:27 pm, edited 1 time in total.
Reason: Stripped [size] tags [Posting Guidelines §1d].
Reason: Stripped [size] tags [Posting Guidelines §1d].
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Re: [filter_location] problem
Why do you store him and unstore him right after that? You can easily store him with kill=no.
And I damned forgot that you wrote there that you needed to find a vacant hex.
And I damned forgot that you wrote there that you needed to find a vacant hex.
Re: [filter_location] problem
trewe had the right idea. I don't see any problem with his code... it should work as a solution to the original question you asked.
But I see in the final version you decided to find hexes that are farther away when the search fails at radius of 7, and you also changed the terrain string.
But I see in the final version you decided to find hexes that are farther away when the search fails at radius of 7, and you also changed the terrain string.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: [filter_location] problem
That's right.Sapient wrote:trewe had the right idea. I don't see any problem with his code... it should work as a solution to the original question you asked.
I gave Trewe's code another try, and indeed it works perfect. (and it is much shorter than my solution)

I must have done something wrong yesterday.

@Treve: Sorry for saying your code-attempt doesn't work.
@Anonymissimus: The tip with the labels is brilliant.
Thank you all for your help.

Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR