advancement filter query

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
Spannerbag
Posts: 539
Joined: December 18th, 2016, 6:14 pm
Location: Yes

advancement filter query

Post by Spannerbag »

Hi,

Edit: just tried the hack below and it seems to work so I have that as a backstop :)

I have some custom AMLAs just wondered if there's an easier way than below to do what I want?

Originally I wanted to allow/enable the advancement when a specific unit variable=1 or always for a specific unit, namely:

Code: Select all

  [advancement]
    [filter]
      id=Magnus
      [or]
      [filter_wml]
        [variables]
          cascade=1
        [/variables]
      [/filter_wml]
      [/or]
    [/filter]
This seems to work fine.

However me being me I have added a few more features and now need to test for greater_than.

I tried:

Code: Select all

  [advancement]
    [filter]
      id=Magnus
      [or]
      [filter_wml]
        [variables]
          cascade>1		# ">" not "="
        [/variables]
      [/filter_wml]
      [/or]
    [/filter]
and get an error when I load the campaign. As the variable can only (so far) be 0,1 or 2 I suppose I could use:

Code: Select all

  [advancement]
    [filter]
      id=Magnus
      [or]
      [filter_wml]
        [variables]
          cascade=1
        [/variables]
      [/filter_wml]
      [/or]
      [or]
      [filter_wml]
        [variables]
          cascade=2
        [/variables]
      [/filter_wml]
      [/or]
    [/filter]
However there must (I guess) be a more general form of testing this variable but I can't seem to find the relevant documentation?
Any suggestions?

Cheers!
-- Spannerbag
Last edited by Spannerbag on February 25th, 2023, 11:22 pm, edited 1 time in total.
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Straff
Posts: 87
Joined: September 27th, 2020, 2:53 pm

Re: advancement filter query

Post by Straff »

Can yu use

Code: Select all

require_amla
?
User avatar
Spannerbag
Posts: 539
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: advancement filter query

Post by Spannerbag »

Straff wrote: February 25th, 2023, 11:05 pm Can yu use

Code: Select all

require_amla
?
I use that as well :D

Edit - best explain, the cascade variable acts as an on/off switch;
=0 -> off
=1 -> level 1 enabled
=2 -> level 2 enabled

Issue is that with level 2 enabled I need to allow a unit that has not yet taken level 1 to do so, so it isn't level 2 that's the problem but rather level 1.

Or, to put it another way, whether or not level 2 is available depends on that unit having level 1 plus level 2 being generally available.
However when level 2 is available if a unit has not yet obtained level one then only level one should be available for that unit.
require_amla forces the unit to take level 2 only when level 1 is first obtained but for level 1 I need to check if level 1 or level 2 are generally available (yes, I know that there are other ways to do this but I'd rather use this way if possible as there's loads of gnarly code already in this campaign :augh: ).

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
gnombat
Posts: 710
Joined: June 10th, 2010, 8:49 pm

Re: advancement filter query

Post by gnombat »

Spannerbag wrote: February 25th, 2023, 10:59 pm I tried:

Code: Select all

  [advancement]
    [filter]
      id=Magnus
      [or]
      [filter_wml]
        [variables]
          cascade>1		# ">" not "="
        [/variables]
      [/filter_wml]
      [/or]
    [/filter]
and get an error when I load the campaign.
Yes, that couldn't possibly work - WML is fundamentally a very simple language and it has no idea what symbols like < or > mean. (These are, in fact, invalid syntax.)

I haven't tested it, but couldn't you use [variable], together with greater_than?
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: advancement filter query

Post by Toranks »

Code: Select all

[variable]
 name=unit.variables.cascade
 greather_than=1
[variable]
(instead of use unit you can [store_unit] on another variable if necessary)
But this is conditionalWML, and not StandardUnitFilter, so it must be used in another way, for example with an event.
User avatar
Ravana
Forum Moderator
Posts: 3017
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: advancement filter query

Post by Ravana »

There is cleaner way to use formulas now but old way should still work "if(($this_unit.variables.AE_imp_rune_end -1 > -1), 1, 0)"

-1 was important to include because otherwise game crashed if variable was missing.
User avatar
Spannerbag
Posts: 539
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: advancement filter query

Post by Spannerbag »

gnombat wrote: February 26th, 2023, 1:06 am
Spannerbag wrote: February 25th, 2023, 10:59 pm I tried:

Code: Select all

...
          cascade>1		# ">" not "="
...
and get an error when I load the campaign.
Yes, that couldn't possibly work - WML is fundamentally a very simple language and it has no idea what symbols like < or > mean. (These are, in fact, invalid syntax.)

I haven't tested it, but couldn't you use [variable], together with greater_than?
I'll try that but I assumed as textual rather than symbolic notation worked for equality (i.e. "=" not "equals") then for consistency I should use ">" not "greater_than". However "=" and ">" work in formula syntax so I thought it worth a shot here.

Bear in mind I'm working inside a [filter] inside [advancement], so I don't have access to [filter_condition] (I assume, haven't tried tbh) and thereby [variable].

Thanks for the reply.

Cheers,
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 539
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: advancement filter query

Post by Spannerbag »

Toranks wrote: February 26th, 2023, 8:46 am

Code: Select all

[variable]
 name=unit.variables.cascade
 greather_than=1
[variable]
(instead of use unit you can [store_unit] on another variable if necessary)
But this is conditionalWML, and not StandardUnitFilter, so it must be used in another way, for example with an event.
Thanks for the input, but as you say I I can't use this inside [advancement][filter]?
I'd need [filter_condition] - which I haven't tried but might be recognised by [advancement].
I already have a plethora of weird and wonderful events scattered about - I'm amazed the engine hasn't had a nervous breakdown! :)

Thanks for replying.

Cheers,
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 539
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: advancement filter query *FIXED*

Post by Spannerbag »

Ravana wrote: February 26th, 2023, 9:23 am There is cleaner way to use formulas now but old way should still work "if(($this_unit.variables.AE_imp_rune_end -1 > -1), 1, 0)"

-1 was important to include because otherwise game crashed if variable was missing.
Thanks, I'll try it out.

...

Y'know, I really should properly read the documentation. Ive used formulas in [filter] but missed something.

The following worked exactly as I wanted and is generalised, so if I extend this advancement even further (as is likely when I get round to AfterEI v2) this code hopefully will work unchanged. Thanks for giving me a prod to revisit formulas!

Code: Select all

  [advancement]
    [filter]
      id=Magnus
      [or]
         formula="wml_vars.cascade > 0"
      [/or]
    [/filter]
and

Code: Select all

  [advancement]
    [filter]
      id=Magnus
      [or]
         formula="wml_vars.cascade > 1"
      [/or]
    [/filter]
Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Post Reply