Quantcast
Channel: The Battle for Wesnoth Forums
Viewing all articles
Browse latest Browse all 1444

Lua Labs • Re: How to store unit using custom wml tag

$
0
0
If you're asking how to store a unit in a WML variable from Lua, like [store_unit] does:

Code:

local unit = wesnoth.units.find "unit_id" -- get the unit however you want, this example looks it up by its IDwml.variables["your.variable[2].path"] = unit.__cfg
If you're asking how to find a unit based on the content of the ActionWML tag, like [message] does:

Code:

function wesnoth.wml_actions.your_tag(cfg)local unit = wesnoth.units.find(cfg)[1] -- this assumes you want to take the first match – find returns all matching units as an array-- do stuff with unit hereend
Note that [message] is more complicated than that in order to handle the speaker= key, which isn't part of StandardUnitFilter. So, if you use the above example, you can't use speaker=. If you want, you can look at the implementation of the [message] tag in data/lua/wml/message.lua, but be warned that it is very complicated in order to handle a wide variety of situations.

Statistics: Posted by Celtic_Minstrel — Today, 4:49 am



Viewing all articles
Browse latest Browse all 1444

Trending Articles