Filters help needed

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Shanjaq
Posts: 8
Joined: November 25th, 2008, 9:10 am

Filters help needed

Post by Shanjaq » January 15th, 2018, 4:06 am

Hi all, I'm having the some difficulty getting simple filters to work. Here is what I did:

abilities.cfg

Code: Select all

#define ABILITY_VINEGUARD
	[vineguard]
		name= _ "vineguard"
		description= _ "snags enemies with vines"
        affect_self=yes
	[/vineguard]
#enddef
some_unit.cfg

Code: Select all

	[abilities]
	{ABILITY_VINEGUARD}
	[/abilities]
...

[event]
	name=moveto
	first_time_only=no
	id=test1

	[store_unit]
		variable=filtered_units
		[filter]
			ability=vineguard
		[/filter]
	[/store_unit]


	{FOREACH filtered_units i}
		{VARIABLE_OP filtered_units[$i].defense.forest value 0}
		[unstore_unit]
			variable=filtered_units[$i]
			find_vacant=no
			text= _ "-16"
			{COLOR_HEAL}
		[/unstore_unit]
	{NEXT i}
	{CLEAR_VARIABLE filtered_units}
[/event]

I'm using the text popup to highlight units filtered, which shows the above script running for all unit moves as if unfiltered. The wiki did not explain where to put the event so I tossed it in with the unit def above where its [/unit] block terminates. Is there any way to actually Debug scripts in-game?
Last edited by Shanjaq on January 15th, 2018, 8:05 am, edited 1 time in total.

User avatar
Ravana
Moderator
Posts: 1887
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filters. Refuse. To. Work.

Post by Ravana » January 15th, 2018, 4:28 am

ability=vineguard filter doesnt match any units. If you want to use ability= you need to use ability id there, and vineguard doesnt have id. So you need to add id= for your ability.

Shanjaq
Posts: 8
Joined: November 25th, 2008, 9:10 am

Re: Filters. Refuse. To. Work.

Post by Shanjaq » January 15th, 2018, 4:57 am

Ah thanks Ravana, when I added an id=vineguard to the ability it started working (I saw the numbers pop up on every unit with "vineguard" ability.)

So now as I try filtering for units adjacent to units with the vineguard ability, the following filter code causes all units in the map to popup numbers regardless of adjacency, ability or side:

Code: Select all

	[store_unit]
		variable=vineguarded_units
		[filter]
			[filter_adjacent]
				ability=vineguard
				is_enemy=no
			[/filter_adjacent]
		[/filter]
	[/store_unit]
(no changes to the rest of the code apart from changing the unit storage variable to "vineguarded_units")

it seems like the outer filter element is grabbing all units and disregarding the filter_adjacent element? I am trying to follow the "[filter_adjacent]" section of the wiki here:
https://wiki.wesnoth.org/FilterWML/Exam ... r_adjacent.

Also tried like this:

Code: Select all

	[store_unit]
		variable=vineguarded_units
		[filter_adjacent]
			ability=vineguard
		[/filter_adjacent]
	[/store_unit]
and many other obvious parameters by themselves like "is_enemy=no" with the same result. it's as if [filter_adjacent] does not actually use any of the parameters given? pls help :?

User avatar
Samonella
Posts: 359
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Filters. Refuse. To. Work.

Post by Samonella » January 15th, 2018, 7:30 am

Shanjaq wrote:I have been booting the game nonstop for hours for days and getting nowhere.
You can save some time (not a lot) by pressing F5 from the main menu. It's a little faster than completely closing and restarting.
Shanjaq wrote:Is there any way to actually Debug scripts in-game?
I like to use the inspector window; you can type :inspect after entering debug mode with :debug to look at variables, and even better is to use [inspect] to make the same window open at any point in the event. Course, that won't help much if you already know that all units are getting stored.

Your first code in your second post looks right to me, I'd expect it to store all units that are adjacent to an allied vineguard. Though your event will fire whenever any unit moves, even those that won't end up getting stored.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG

User avatar
zookeeper
WML Wizard
Posts: 9739
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Filters help needed

Post by zookeeper » January 15th, 2018, 9:46 am

I don't know what your ability is intended to actually do, but there's no good way to do it in 1.12; you'll always end up disabling undo when making moves that cause the ability to start/stop affecting a unit. In 1.13 you can do it by using [on_undo] and [on_redo], but it's pretty complicated (see the support ability in UtBS).

Shanjaq
Posts: 8
Joined: November 25th, 2008, 9:10 am

Re: Filters help needed

Post by Shanjaq » January 15th, 2018, 9:06 pm

The ability is supposed to be mechanically the same as Leadership, but improve defense for adjacent units on forest tiles instead of boosting their damage.

User avatar
zookeeper
WML Wizard
Posts: 9739
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Filters help needed

Post by zookeeper » January 15th, 2018, 11:30 pm

Shanjaq wrote:The ability is supposed to be mechanically the same as Leadership, but improve defense for adjacent units on forest tiles instead of boosting their damage.
Then I think the only way to do it properly is to use events to make sure all attacks of all units receive an invisible weapon special that decreases their CtH against those units. It's a bit icky, but possible.

Shanjaq
Posts: 8
Joined: November 25th, 2008, 9:10 am

Re: Filters help needed

Post by Shanjaq » January 17th, 2018, 6:50 am

Quick question: Is [filter_adjacent] available in version 1.1.11?

it seems to match all units no matter what I try to filter on, for example:

Code: Select all

   [store_unit]
      variable=filtered_units
      [filter_adjacent]
         ability=vineguard
      [/filter_adjacent]
   [/store_unit]

User avatar
Ravana
Moderator
Posts: 1887
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filters help needed

Post by Ravana » January 17th, 2018, 6:53 am

[store_unit] expects [filter].

Shanjaq
Posts: 8
Joined: November 25th, 2008, 9:10 am

Re: Filters help needed

Post by Shanjaq » January 17th, 2018, 7:06 am

is it not possible to store found adjacent units? I searched for "store_unit filter_adjacent" and saw similar being used but it's still matching all units whether a vineguard unit even exists or not:

Code: Select all

	[store_unit]
		[filter]
			[filter_adjacent]
				ability=vineguard
			[/filter_adjacent]
		[/filter]
		kill=no
		variable=filtered_units
	[/store_unit]

User avatar
Ravana
Moderator
Posts: 1887
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filters help needed

Post by Ravana » January 17th, 2018, 7:32 am

Doing quick test lua wesnoth.wml_actions.store_unit{variable="_",T.filter{T.filter_adjacent{canrecruit=true}}} (those adjacent to leaders), only matches those that it should. It seems then that your filter is correct.

Shanjaq
Posts: 8
Joined: November 25th, 2008, 9:10 am

Re: Filters help needed

Post by Shanjaq » January 17th, 2018, 7:50 am

ok, I tried replacing my filter with:

Code: Select all

lua wesnoth.wml_actions.store_unit{variable="filtered_units",T.filter{T.filter_adjacent{canrecruit=true}}}
and running wesnoth.exe crashed with error:
error general: Warning: Errors occurred while loading game configuration files: 'Unexpected characters after variable name (expected , or =) at data/units/Monster_Lavaguard.cfg:194 included from data/units.cfg:10 included from data/game.cfg:135
I also tried:

Code: Select all

	[store_unit]
		[filter]
			[filter_adjacent]
				canrecruit=true
			[/filter_adjacent]
		[/filter]
		kill=no
		variable=filtered_units
   [/store_unit]
and it still matched all units no matter how far from the leader. is it possible that placing the filter in a "moveto" event somehow changes the behavior of filters?

full event code:
Spoiler:
is it also possible that [filter_adjacent] is not available on 1.1.11 (at least that's what it says in the lower left corner of the main menu?)

also, :debug and :inspect do nothing in any game mode (SP, tutorial, MP-vs-AI, etc.)

User avatar
Ravana
Moderator
Posts: 1887
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filters help needed

Post by Ravana » January 17th, 2018, 8:18 am

That lua line is for debug only, after :debug you can put that to command line - basically allows testing without reloading wesnoth.

For normal code it would be written as

Code: Select all

[store_unit]
  variable="_"
  [filter]
	 [filter_adjacent]
		canrecruit=yes
	 [/filter_adjacent]
  [/filter]
[/store_unit]
If you somehow did happen to find 1.1.11, then I suggest you instead install something from 1.12 or 1.13.

Your moveto event does not break filters.

Post Reply