wesnoth.get_units with radius

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

Moderator: Forum Moderators

Post Reply
User avatar
WhiteWolf
Forum Moderator
Posts: 763
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

wesnoth.get_units with radius

Post by WhiteWolf »

Hi,

Sorry for the newbie lua question.
I'd like to use wesnoth.get_units to get an array of a units for in an area with a given radius around a tile. Something like:

Code: Select all

local inrange = wesnoth.get_units{x=27, y=10, radius=10}
But of course radius is not in SUF, it needs to go within a [filter_location] inside the SUF. What would be the syntax to achieve this? Unfortunately I've been unable to figure it out.
Thanks!
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Toranks
Posts: 104
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: wesnoth.get_units with radius

Post by Toranks »

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

Re: wesnoth.get_units with radius

Post by Ravana »

WML tag
[a]
b=c
[/a]
is written in Lua as {"a", {b="c"}}.
User avatar
WhiteWolf
Forum Moderator
Posts: 763
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: wesnoth.get_units with radius

Post by WhiteWolf »

Got it, thank you!
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Celtic_Minstrel
Developer
Posts: 2007
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: wesnoth.get_units with radius

Post by Celtic_Minstrel »

No no no no no…

Ravana is technically correct, but I don't recommend doing what he said. It's confusing.

Instead, write it like this:

Code: Select all

wml.tag.a{b = "c"}
It expands to the exact same thing but is easier to understand what on earth it's doing.

So, to take your example:

Code: Select all

local inrange = wesnoth.get_units{x=27, y=10, wml.tag.filter_location{radius=10}}
It's also common to shorten wml.tag to just T by defining a local variable.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
Post Reply