[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: 9
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: 4050
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: 9
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: 1522
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: 403
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: 2242
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: 738
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: 1522
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel » October 22nd, 2019, 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: 2242
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [move_unit] exactly one hex back

Post by Ravana » October 22nd, 2019, 6:25 am

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

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

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel » October 24th, 2019, 1:57 am

I'm pretty sure it's guaranteed to be in sync after an attack? That may not have been the case in 1.12, but I'm fairly sure it's true in 1.14 – otherwise the backstab special probably wouldn't work properly.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

gfgtdf
Developer
Posts: 1189
Joined: February 10th, 2013, 2:25 pm

Re: [move_unit] exactly one hex back

Post by gfgtdf » October 24th, 2019, 2:30 am

Hmm yes iirc you changed it to be set before every attack, still it's not set before predictions, this probably also effects the lua wesnoth.simulate_combat function by the way leading to possible oos (although that function is _mostly_ used in the air code where it if course won't cause oos(
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.

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

Re: [move_unit] exactly one hex back

Post by josteph » October 24th, 2019, 5:08 am

gfgtdf wrote:
October 24th, 2019, 2:30 am
Hmm yes iirc you changed it to be set before every attack, still it's not set before predictions, this probably also effects the lua wesnoth.simulate_combat function by the way leading to possible oos (although that function is _mostly_ used in the air code where it if course won't cause oos(
"air code"?

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

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel » October 24th, 2019, 12:15 pm

I think he means AI code.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

Post Reply