Lua location syntax
Moderator: Forum Moderators
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Lua location syntax
Here it appear the interpreter parses the arguments to animator:add(), and we see them parsed in the same order they are listed in the wiki, except the first one is not facing, but target. I don't see anything that would accept facing.Celtic_Minstrel wrote: ↑June 3rd, 2024, 3:26 am The documentation is here for the record.
It should accept "facing" which is a direction, egwhite_haired_uncle wrote: ↑June 2nd, 2024, 12:03 pm Hmm. I think we can tell that the wiki is wrong and it should be "target", not "facing" from src/scripting/game_lua_kernel.cpp. And it appears target= needs a location, but I can't find a solid definition of location.'nw'
. Thus this seems like it might be a bug. It's fine for it to accept "target" as an alternative though, taking a location. From the sounds of it, only the latter is currently supported?
https://github.com/wesnoth/wesnoth/blob ... l.cpp#L268
That's what I thought, but according to OP passingCeltic_Minstrel wrote: ↑June 3rd, 2024, 3:26 am A location is either a two-element array, eg{3, 5}
, or anything that containsx
andy
tags, eg{x = 3, y = 5}
. It does not requireterrain
, and usually does not have that. There's no need to usewesnoth.map.get
orwesnoth.map.find
to get a hex reference.
{x = 3, y = 5}
doesn't work, but the interesting method of get/find/etc does. I suspect it may actually work because he sets unit.facing (which is attacker.facing as well I believe). My theory is that it's setting the unit facing=direction that's actually making the animation look right, while target=location is either being ignored or not provided correctly when it doesn't work.Speak softly, and carry Doombringer.
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Lua location syntax
That was a general statement on what constitutes a location in Wesnoth.ZombieKnight wrote: ↑June 3rd, 2024, 5:25 am If you look-up for the code I've posted, you discover, you aren't right (that code is from animate_unit implementation).
(Or it just doesn't work in animator)
Yes, I saw that. I'm saying that it should accept facing, not that it does.white_haired_uncle wrote: ↑June 2nd, 2024, 12:03 pm Here it appear the interpreter parses the arguments to animator:add(), and we see them parsed in the same order they are listed in the wiki, except the first one is not facing, but target. I don't see anything that would accept facing.
https://github.com/wesnoth/wesnoth/blob ... l.cpp#L268
He said that get/find doesn't work. The only thing that worked was setting the facing direction manually on the unit before animating. However, that same code also passes the facing direction as the target, which doesn't seem like it could work.white_haired_uncle wrote: ↑June 2nd, 2024, 12:03 pm That's what I thought, but according to OP passing{x = 3, y = 5}
doesn't work, but the interesting method of get/find/etc does. I suspect it may actually work because he sets unit.facing (which is attacker.facing as well I believe). My theory is that it's setting the unit facing=direction that's actually making the animation look right, while target=location is either being ignored or not provided correctly when it doesn't work.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Lua location syntax
True, it doesn't work without manually setting facing, it's weird that core code passes the parameter then.Celtic_Minstrel wrote: ↑June 3rd, 2024, 1:08 pm He said that get/find doesn't work. The only thing that worked was setting the facing direction manually on the unit before animating. However, that same code also passes the facing direction as the target, which doesn't seem like it could work.
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Lua location syntax
ZombieKnight wrote: ↑June 3rd, 2024, 1:25 pmTrue, it doesn't work without manually setting facing, it's weird that core code passes the parameter then.Celtic_Minstrel wrote: ↑June 3rd, 2024, 1:08 pm He said that get/find doesn't work. The only thing that worked was setting the facing direction manually on the unit before animating. However, that same code also passes the facing direction as the target, which doesn't seem like it could work.
What happens if you set facing to the wrong direction, and then pass target={x=X, y=Y} (with target set to the correct location)?
Speak softly, and carry Doombringer.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Lua location syntax
Haven't tryied, but when I comment out the line where I set unit's facing (line facing='ne' for example)white_haired_uncle wrote: ↑June 3rd, 2024, 10:39 pm What happens if you set facing to the wrong direction, and then pass target={x=X, y=Y} (with target set to the correct location)?
Units facing doesn't change.
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Lua location syntax
I looked into this a bit, and I got to here before I got in over my head.Celtic_Minstrel wrote: ↑June 3rd, 2024, 3:26 am The documentation is here for the record.
It should accept "facing" which is a direction, egwhite_haired_uncle wrote: ↑June 2nd, 2024, 12:03 pm Hmm. I think we can tell that the wiki is wrong and it should be "target", not "facing" from src/scripting/game_lua_kernel.cpp. And it appears target= needs a location, but I can't find a solid definition of location.'nw'
. Thus this seems like it might be a bug. It's fine for it to accept "target" as an alternative though, taking a location. From the sounds of it, only the latter is currently supported?
https://github.com/wesnoth/wesnoth/blob ... #L377-L434
It looks to me like the location provided by target (and I suspect indirectly provided by facing if it were implemented) is never getting used. It appears the second_location is only used when there is a [filter_second] in the animation.
It looks like in an actual attack, unit.facing is set just before the animation is called (which seems right, since the attacker and defender end up facing each other afterwards):
https://github.com/wesnoth/wesnoth/blob ... #L631-L633
It seems to me like the easy "fix" here would just be to have create_animator set unit.facing, at least for flag=attack, when provided with target/facing at least. However, that's probably a one-off solution for one end case, and I'm not even sure about the side effects of that one case (for example, should facing be set back after the animation? my gut says no, because that's not done for a "real" attack?).
I suppose what I should do is raise this as an issue and add a comment as such to the wiki.
Speak softly, and carry Doombringer.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Lua location syntax
I see...
Thats weird...
Unfortunately I haven't done any further research and so I can't really help you now.
But issue and wiki edit would be welcomed ^^.
Thats weird...
Unfortunately I haven't done any further research and so I can't really help you now.
But issue and wiki edit would be welcomed ^^.
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Lua location syntax
Speak softly, and carry Doombringer.