[SOLVED] [filter_location] problem

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
User avatar
Adamant14
Posts: 970
Joined: April 24th, 2010, 1:14 pm

[SOLVED] [filter_location] problem

Post by Adamant14 »

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

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
User avatar
Dugi
Posts: 4965
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: [filter_location] problem

Post by Dugi »

I am not sure about this, but this might work.
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]
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: [filter_location] problem

Post by Anonymissimus »

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.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
trewe
Translator
Posts: 122
Joined: December 24th, 2012, 5:37 pm
Location: Portugal
Contact:

Re: [filter_location] problem

Post by trewe »

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]
User avatar
Adamant14
Posts: 970
Joined: April 24th, 2010, 1:14 pm

Re: [filter_location] problem

Post by Adamant14 »

Thank you all for your answers, but sadly non of them did work for me. :(

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 found this out by spending hours and hours trying out every possible combination. :roll:
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].
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
Dugi
Posts: 4965
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: [filter_location] problem

Post by Dugi »

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.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [filter_location] problem

Post by Sapient »

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.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Adamant14
Posts: 970
Joined: April 24th, 2010, 1:14 pm

Re: [filter_location] problem

Post by Adamant14 »

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.
That's right.
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. :oops:

@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
Post Reply