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: 769
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!
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
User avatar
Toranks
Translator
Posts: 168
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: 2997
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: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: wesnoth.get_units with radius

Post by WhiteWolf »

Got it, thank you!
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
User avatar
Celtic_Minstrel
Developer
Posts: 2195
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.
Former maintainer of Steelhive.
Post Reply