Changing the direction a unit is facing
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Changing the direction a unit is facing
Hi. I need a unit to change their facing without moving into a new hex. The unit needs to remain where they are, but facing
I even tried
I'm using version 1.15.6. Thanks for your help.
sw
instead of se
. It's for a cut-scene between two units speaking to one another.I even tried
[redraw][/redraw]
, to force the screen to update the units, thinking that might help. But no luck.I'm using version 1.15.6. Thanks for your help.
Code: Select all
[event]
name=turn 3
[unit]
side=1
type="Elvish Shaman"
id="Fira"
name= _ "Fira"
x,y=1,5
facing=se
[/unit]
[message]
speaker=Fira
message= _ "Hello? Anybody here?"
[/message]
[modify_unit]
[filter]
id=MyLeader
[/filter]
facing=sw # the unit turns to face the person who just arrived
[/modify_unit]
[redraw][/redraw]
[message]
speaker=MyLeader
message= _ "Welcome."
[/message]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: Changing the direction a unit is facing
Odd. Based on this snippet in the thread https://forums.wesnoth.org/viewtopic.php?f=21&t=53463, I would have expected that to work.
Try changing the sw temporarily to
The other thing I can think of that you might try is if your leader has some animation that could be interpreted as surprise, waving, or snapping to attention, then you could try using [animate_unit] (https://wiki.wesnoth.org/InterfaceActio ... te_unit.5D) to play that animation, to force it to reconsider what it looks like. I don't know if it would work or not, but you could try it.
Code: Select all
[modify_unit]
[filter]
x,y=$x2,$y2
[/filter]
facing=$-unit.facing
[/modify_unit]
$-unit.facing
, and see whether it works to do that. If that makes the unit turn completely around, then the "sw" doesn't work (I don't know why it wouldn't work, but you never know...), whereas if it does nothing, then the rest of the snippet doesn't work.The other thing I can think of that you might try is if your leader has some animation that could be interpreted as surprise, waving, or snapping to attention, then you could try using [animate_unit] (https://wiki.wesnoth.org/InterfaceActio ... te_unit.5D) to play that animation, to force it to reconsider what it looks like. I don't know if it would work or not, but you could try it.
Re: Changing the direction a unit is facing
Duuude! Your code worked!
$-
..?? How did you learn that stuff? I'm glad that you think my code should've worked. I suspect there are bugs in 1.15.6 related to
facing
. In 1.15.5, I noticed two facing-related bugs. 1) A unit created in
[side]
would face SE, regardless of the facing=
(fixed in 1.15.6).2) A newly recruited unit would always face SE, not a random direction (not fixed yet).
Mainline has a macro that changes a unit's facing:
{MODIFY_UNIT id=MyLeader facing sw}
. It works in add-ons, too. But I try to not use macros until I've examined the code myself, and I couldn't find the macro's code within the labyrinth of mainline folders.I was toying with animating the unit turning his head, but decided against it. I have too many sprites that still need attack animations.
Thanks!
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: Changing the direction a unit is facing
Well, I remembered testing out the moving-through-units code, and noticing that it was very neat when the unit turned around, so I tracked it down in the WML workshop again.
The MODIFY_UNIT macro is in data/core/macros/utils.cfg, if you want to look at it.
Edit: ah, I should note that
The MODIFY_UNIT macro is in data/core/macros/utils.cfg, if you want to look at it.
Edit: ah, I should note that
$-unit.facing
seems to turn the unit completely around. So if it was facing SE, now it faces NW, if it was facing N, now it faces S, and so on. This means it will only work in a limited set of circumstances where the unit was facing partially sideways (se, sw, ne, nw) and only has south/southeast-facing graphics. That way, even if it thinks it's now facing nw, in practice, it appears to look sw, which is a horizontal flip of se, and so on. So it's a bit of a hacky and finicky solution, but it's okay so long as it works in your case.Re: Changing the direction a unit is facing
I actually had checked that file. I assumed it wasn't the one I was looking for because I didn't see the word
Here's the macro, should anyone need it.
facing
anywhere. Oops. I now realize my mistake.Here's the macro, should anyone need it.
Code: Select all
#define MODIFY_UNIT FILTER VAR VALUE
# Alters a unit variable (such as unit.x, unit.type,
# unit.side), handling all the storing and unstoring.
#
# Example that flips all spearmen to side 2:
#! {MODIFY_UNIT type=Spearman side 2}
[store_unit]
[filter]
{FILTER}
[/filter]
variable=MODIFY_UNIT_store
kill=yes
[/store_unit]
[foreach]
array=MODIFY_UNIT_store
[do]
[set_variable]
name=this_item.{VAR}
value={VALUE}
[/set_variable]
[unstore_unit]
variable=this_item
find_vacant=no
[/unstore_unit]
[/do]
[/foreach]
{CLEAR_VARIABLE MODIFY_UNIT_store}
#enddef
Last edited by Helmet on November 12th, 2020, 10:19 pm, edited 2 times in total.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: Changing the direction a unit is facing
Well, it changes whatever "var" is to the value of "value". So when you write facing and sw, it changes facing to sw. It's a very open-ended macro!
(Hey, does the modify_unit macro actually work? If so, then the fact that it works but regular facing=sw doesn't work would probably be very useful information when reporting it as an issue.)
(Hey, does the modify_unit macro actually work? If so, then the fact that it works but regular facing=sw doesn't work would probably be very useful information when reporting it as an issue.)
Re: Changing the direction a unit is facing
Yes, it works. I reported the bug about myPilauli wrote: ↑November 12th, 2020, 10:17 pm Well, it changes whatever "var" is to the value of "value". So when you write facing and sw, it changes facing to sw. It's a very open-ended macro!
(Hey, does the modify_unit macro actually work? If so, then the fact that it works but regular facing=sw doesn't work would probably be very useful information when reporting it as an issue.)
facing
code not working a few minutes ago. I'll add that information to the report.Thanks for explaining. I was wondering if it mirrored the unit's direction.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Celtic_Minstrel
- Developer
- Posts: 2235
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Changing the direction a unit is facing
What the heck? That should never work. It's supposed to be
-$unit.facing
, not $-unit.facing
. The latter shouldn't even be recognized as a variable substitution.Re: Changing the direction a unit is facing
Hm. I just tested them both, and they both work. TheCeltic_Minstrel wrote: ↑November 14th, 2020, 8:14 pm What the heck? That should never work. It's supposed to be-$unit.facing
, not$-unit.facing
. The latter shouldn't even be recognized as a variable substitution.
-$
version makes a little more sense, now that you mention it. It's like the minus sign is saying, "Flip the following variable," instead of, "A variable is forthcoming, flip it, and here it is."Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Celtic_Minstrel
- Developer
- Posts: 2235
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Changing the direction a unit is facing
I just tested the WMl variable interpolation system on the latest master, and
Side note: If you want to turn the unit relative to its current direction, you can also use
$-unit.facing
does not do anything. I suspect the only reason it appears to work is because the engine sees an invalid direction and replaces it with a default value that coincidentally matches what you want to see.Side note: If you want to turn the unit relative to its current direction, you can also use
$unit.facing:cw
(for a clock-wise turn) or $unit.facing:ccw
(for a counter-clockwise turn).Re: Changing the direction a unit is facing
I just tested them and they flip a unit to the opposite direction. Thanks.Celtic_Minstrel wrote: ↑November 15th, 2020, 12:41 am Side note: If you want to turn the unit relative to its current direction, you can also use$unit.facing:cw
(for a clock-wise turn) or$unit.facing:ccw
(for a counter-clockwise turn).
I don't understand how they work, though.
I used debug/inspect to check the variables before and after. When I used
$unit.facing:cw
on a unit, ne
became sw
. I expected ne
to become se
when the direction rotated one hex-side clockwise. So I assumed the direction must rotate 3 hex-sides clockwise. So I put two
$unit.facing:cw
back to back, expecting the unit to return to it's original direction. But it didn't. Geez, it seems that every time I learn one new thing about WML, two or more questions arise from the darkness!Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Celtic_Minstrel
- Developer
- Posts: 2235
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Changing the direction a unit is facing
This is what's supposed to happen. If it's not working, either there's a bug somewhere or something changes the unit's direction between when you saw that it's
ne
and when you modified its direction.Re: Changing the direction a unit is facing
Oops, I made a mistake. I neglected to comment-out this macro:
Anyhow...I commented-out the macro and retested
Side note: Is there a way for me to make macros appear green (or some other color) in the syntax highlighter you made? I have no idea where to start. I'd also like to add
{MODIFY_UNIT id=MyLeader facing sw}
and it turned the unit sw
. I happen to use the old TextWrangler/BBCode syntax highlighter you made. I love it, but if there is one feature I wish it had, it would be that macros had a color other than light purple, the same color used for comments. Sometimes my macros are hard to notice amidst comments.Anyhow...I commented-out the macro and retested
facing=$unit.facing:cw
. It turns out that it doesn't work at all. I reported the bug.Side note: Is there a way for me to make macros appear green (or some other color) in the syntax highlighter you made? I have no idea where to start. I'd also like to add
[elseif]
to the recognized list of tags.Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: Changing the direction a unit is facing
[modify_unit] facing has problems in 1.15 see https://github.com/wesnoth/wesnoth/issues/4978
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
- Celtic_Minstrel
- Developer
- Posts: 2235
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact: