filtering units by WML variable

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
denispir
Posts: 184
Joined: March 14th, 2013, 12:26 am

filtering units by WML variable

Post by denispir »

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?
Thank you!
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: filtering units by WML variable

Post by Celtic_Minstrel »

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 [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]
If you want to match a unit that has the 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]
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 [filter_wml] besides the [variables] tag, then yes, the unit would be converted to a WML variable first.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
denispir
Posts: 184
Joined: March 14th, 2013, 12:26 am

Re: filtering units by WML variable

Post by denispir »

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…
Well, I want to indicate units by WML variables directly(not by filtering an internal variable), Just as by listing a series of ids:

Code: Select all

[move_toward]
    unit_vars = troll1, troll2, troll3       # 3 var names
    x, y = 12, 34                                # goal
[/move_toward]
(Sh*t ! indentation is buggy in the edit frame...)
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: filtering units by WML variable

Post by Ravana »

Then troll1.id has unit id, which you can use for filtering.
User avatar
Pentarctagon
Project Manager
Posts: 5526
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: filtering units by WML variable

Post by Pentarctagon »

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
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: filtering units by WML variable

Post by Celtic_Minstrel »

denispir wrote: November 11th, 2019, 2:52 pm
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…
Well, I want to indicate units by WML variables directly(not by filtering an internal variable), Just as by listing a series of ids:
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.

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.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
denispir
Posts: 184
Joined: March 14th, 2013, 12:26 am

Re: filtering units by WML variable

Post by denispir »

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.
All right, thank you very much!
Post Reply