[move_unit] exactly one hex back

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.
Post Reply
serclino
Posts: 7
Joined: May 18th, 2018, 9:54 pm

[move_unit] exactly one hex back

Post by serclino » October 11th, 2019, 5:58 pm

Hello,

how can I set up following: When player's units reached deep forest in my scenario, I want them to turn back and prevent them to go further to the trees. I already wrote this:

Code: Select all

[event]
	name=enter_hex
	first_time_only=no
	[filter]
		side=1
		x=10
		y=1-10
	[/filter]
	
	[message]
		speaker=unit
		message= _ "We should return back to the main path."
	[/message]
	
	[move_unit]
		x=10
		y=1-10
		
		#Here I don't know what I should write, because I would like to return unit EXACTLY one hex back.
		to_x=
		to_y=
	[/move_unit]
[/event]

So again: I would like to return unit EXACTLY one hex back.

Any ideas, please? Thank you.

User avatar
Pentarctagon
Forum Administrator
Posts: 4012
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: [move_unit] exactly one hex back

Post by Pentarctagon » October 11th, 2019, 6:23 pm

You could use the automatically stored variables y1/y2 and x1/x2.

So maybe something like:

Code: Select all

[move_unit]
	x=$x1
	y=$y1
	to_x=$x2
	to_y=$y2
[/move_unit]
based on what those values should be as per the wiki.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

serclino
Posts: 7
Joined: May 18th, 2018, 9:54 pm

Re: [move_unit] exactly one hex back

Post by serclino » October 12th, 2019, 9:21 am

Pentarctagon: Thank you :) It works.

User avatar
Celtic_Minstrel
Developer
Posts: 1499
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel » October 20th, 2019, 11:49 pm

In 1.15 the following should also work:

Code: Select all

[move_unit]
	x=$x1
	y=$y1
	dir=-$unit.facing
[/move_unit]
Basically, move the unit one space in the direction opposite the direction it's currently facing. But again, unless you patch in the capability (as I did in Black Cross), you need 1.15 for that to work.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

User avatar
octalot
Developer
Posts: 383
Joined: July 17th, 2010, 7:40 pm

Re: [move_unit] exactly one hex back

Post by octalot » October 21st, 2019, 2:42 am

That would need a check for the hex being vacant, as units can move through hexes occupied by other friendly units.

User avatar
Ravana
Forum Moderator
Posts: 2209
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [move_unit] exactly one hex back

Post by Ravana » October 21st, 2019, 6:36 am

Previously unit.facing was unsynced, is that changed now?

User avatar
josteph
Developer
Posts: 729
Joined: August 19th, 2017, 6:58 pm

Re: [move_unit] exactly one hex back

Post by josteph » October 21st, 2019, 11:16 pm

Pretty sure it's still unsynced, and we should really not have synced and unsynced attributes in the same namespace, it should be something like unit.unsynced_facing, unit.unsynced_controller etc.

User avatar
Celtic_Minstrel
Developer
Posts: 1499
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel » Yesterday, 12:32 am

Though it may technically be unsynced, I believe you can at least rely on its value to be effectively synced after a unit has finished moving or attacking?
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

User avatar
Ravana
Forum Moderator
Posts: 2209
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [move_unit] exactly one hex back

Post by Ravana » Yesterday, 6:25 am

It was depending on animation settings, so attacking would be one case to get it out of sync.

Post Reply