filtering units by WML variable
Moderator: Forum Moderators
filtering units by WML variable
I am making a new tag-block [move_units_together] and would like to allow users to indicate the units by WML var names.
- How is it at all possible since a SUF does not have a variable= key? (or I did not find it)
- I know about the sub-tag [filter_wml] but it first converts potential units into a WML var (and complicates, and also does not have a name=key so that it seems users would have to invent a special key for that)
- If I find a way, how then to deal with it on the Lua side. I mean, the docs online about Lua-WML interaction are rather obscure to me. How to do it in this case?
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: filtering units by WML variable
I'm not sure I fully understand your intention, and if I do understand it, it doesn't sound like a very good design, but…
If your question is "how to match units that have a particular variable set", the answer is indeed
If you want to match a unit that has the
These filters won't convert the unit to a WML variable, if I recall correctly – there is an optimization if you're only checking variables. If you had anything else in
If your question is "how to match units that have a particular variable set", the answer is indeed
[filter_wml]
, but the way that works doesn't need a name key. For example, if you wanted to match a unit that has the variable group
set to "squad", then the WML filter would look like this:Code: Select all
[filter_wml]
[variables]
group=squad
[/variables]
[/filter_wml]
group
variable set but don't care about its value, then the WML filter would look like this (requires 1.15):Code: Select all
[filter_wml]
[variables]
glob_on_squad=*
[/variables]
[/filter_wml]
[filter_wml]
besides the [variables]
tag, then yes, the unit would be converted to a WML variable first.Re: filtering units by WML variable
Well, I want to indicate units by WML variables directly(not by filtering an internal variable), Just as by listing a series of ids:Celtic_Minstrel wrote: ↑November 11th, 2019, 1:19 pm I'm not sure I fully understand your intention, and if I do understand it, it doesn't sound like a very good design, but…
Code: Select all
[move_toward]
unit_vars = troll1, troll2, troll3 # 3 var names
x, y = 12, 34 # goal
[/move_toward]
Re: filtering units by WML variable
Then troll1.id has unit id, which you can use for filtering.
- Pentarctagon
- Project Manager
- Posts: 5599
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: filtering units by WML variable
You can access WML variables from lua, so given this is your own custom tag, you should be able to check whatever piece(s) of data you want that are part of the passed in variables.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: filtering units by WML variable
As I suspected… I don't think that's a good design. It requires the designer to first put the units into variables before moving them, which is honestly kind of wasteful, because that variable is actually a copy of the entire unit which you're (probably) not even going to use, since all you're doing is moving the unit.denispir wrote: ↑November 11th, 2019, 2:52 pmWell, I want to indicate units by WML variables directly(not by filtering an internal variable), Just as by listing a series of ids:Celtic_Minstrel wrote: ↑November 11th, 2019, 1:19 pm I'm not sure I fully understand your intention, and if I do understand it, it doesn't sound like a very good design, but…
Anyway, I'm pretty sure your use of
unit_vars
there is equivalent to the SUF find_in
key, with the exception that the latter probably only accepts a single variable rather than a list of variables (so in that case you'd need to store the units all into the same array variable).My recommendation is: just use a SUF to indicate the units. It'll be easier to understand, more efficient, and less awkward for anyone using your tag. And if you don't, it would be rewritten to use one anyway if it were adopted into mainline, so you might as well use one from the start if that's your goal.
Re: filtering units by WML variable
All right, thank you very much!Celtic_Minstrel wrote: ↑November 12th, 2019, 1:36 am My recommendation is: just use a SUF to indicate the units. It'll be easier to understand, more efficient, and less awkward for anyone using your tag. And if you don't, it would be rewritten to use one anyway if it were adopted into mainline, so you might as well use one from the start if that's your goal.