Hi,
I so often need to extract the x,y of a unit that I decided to write a quick WML inline hack to do this.
It works as expected except for units on recall.
Here's the relevant code:
This all works fine (
Ideally I'd like to:![Smile :)]()
[sanity_check]
Is this actually any quicker/more efficient than using
[/sanity_check]
Any help, thoughts, suggestions etc. gratefully received!
Cheers!
-- Spannerbag
I so often need to extract the x,y of a unit that I decided to write a quick WML inline hack to do this.
It works as expected except for units on recall.
Here's the relevant code:
Code:
# unit_xy template## lua: takes a filter and returns first matching unit's x,y## WML uses [get_unit_xy] tag to find (first) matching unit on map## [get_unit_xy]# ... filter (=cfg in lua) ...# [/get_unit_xy]## Sets variables $gux and $guy# These are 0,0 if unit not found, no error is issued... [lua] code = << function wesnoth.wml_actions.get_unit_xy(cfg) local guxy = wesnoth.units.find(cfg) if not guxy[1] then wml.variables.gux = 0 wml.variables.guy = 0 else wml.variables.gux = guxy[1].x wml.variables.guy = guxy[1].y end end >> [/lua]# Our heroes [side] team_name=Goodies user_team_name= _ "Goodies" side=1 x,y=1,1 id=Goody name=_"Goody" type=Spearman controller=human canrecruit=yes recruit=Bowman,Spearman gold=100 [/side]# Enemy side [side] side=2 x,y=44,33 id=Baddy type=Goblin Rouser name= _ "Baddy" canrecruit=yes controller=ai team_name=Baddies user_team_name= _ "Baddies" random_traits=yes recruit=Goblin Spearman,Goblin Impaler gold=100 [/side]# --- Events --- [event] name=side 1 turn 1 {UNIT 1 Mage recall recall (id=testmagegenerate_name=yes)} [/event] [event] name=side 1 turn 2{DEBUG_MSG (_"About to test [get_unit_xy]")} [get_unit_xy]# side=2# [filter_location]# terrain=*^V*# [/filter_location] id=testmage [/get_unit_xy]{DEBUG_MSG (_"Done [get_unit_xy], x=$gux, y=$guy")} [/event]
$gux
and $guy
return values expected) except for recall.Ideally I'd like to:
- Allow the coder to specify a particular WML array variable or default to
gu
if no array specified.
I tried setting$gu.x
and$gu.y
in lua but couldn't get the syntax quite right.
Iswml.array_variables
the right command to do this?
Will keep experimenting when I next get time. - Return
x,y=recall,recall
for units on recall.
E.g. if I recall the mage withid=testmage
on turn 1, it's co-ordinates are correctly reported on turn 2.
However if I leave it on recall I don't getx,y=recall,recall
as expected.
I thought wesnoth.units.find included recall but for me it doesn't seem to work so what am I doing wrong?
(I'm guessing I need to useunstore_unit
or similar to do this but I'm getting out of my depth.)
I can't spend any more time on this now as I have other stuff to do hence this post, hopefully it's a trivial mistake I've made somewhere.

[sanity_check]
Is this actually any quicker/more efficient than using
[store_unit]
to extract the x,y values?[/sanity_check]
Any help, thoughts, suggestions etc. gratefully received!
Cheers!
-- Spannerbag
Statistics: Posted by Spannerbag — Today, 1:09 pm