moveto event with "proximity check"

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
Anagkai
Posts: 54
Joined: February 12th, 2012, 10:05 am

moveto event with "proximity check"

Post by Anagkai » October 13th, 2018, 4:02 pm

I need to check wether a certain unit comes close to another. I first tried using "radius" with the coordinates in the filter but that didn't work (the event never triggers) Now I did the following which triggers even though it shouldn't:

Code: Select all

	[event]
		name=moveto
		first_time_only=no
		[filter]
			id=Henry
			[or]
				role=ash_carrier
			[/or]
		[/filter]
		[if]
			[variable]
				name=ashes_x
				greater_than=$($henry_x-3)
			[/variable]
			[and]
				[variable]
					name=ashes_x
					less_than=$($henry_x+3)
				[/variable]
			[/and]
			[and]					
				[variable]
					name=ashes_y
					greater_than=$($henry_y-3)
				[/variable]
			[/and]
			[and]
				[variable]
					name=ashes_y
					less_than=$($henry_y+3)
				[/variable]
			[/and]
			[then]
				{RETURN_ASHES}
			[/then]
		[/if]
	[/event]
The coordinates are defined as follows:

Code: Select all

		{VARIABLE henry_x 56}
		{VARIABLE henry_y 39}
		{VARIABLE ashes_x -1}
		{VARIABLE ashes_y -1}
Note: the -1 is deliberate, these are set later by an event.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)

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

Re: moveto event with "proximity check"

Post by Ravana » October 13th, 2018, 4:06 pm

Is it intentional that you do not check anything about currently moved units location?

Anagkai
Posts: 54
Joined: February 12th, 2012, 10:05 am

Re: moveto event with "proximity check"

Post by Anagkai » October 13th, 2018, 4:13 pm

The thing is, that it should work both ways, that means, no matter which of the two units did move respectively. That's why I thought it would be best to keep track of the coordinates and compare them if either of the two units has moved.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)

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

Re: moveto event with "proximity check"

Post by Ravana » October 13th, 2018, 4:20 pm

Then you need to do the check after you update their coordinates.

User avatar
zookeeper
WML Wizard
Posts: 9739
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: moveto event with "proximity check"

Post by zookeeper » October 13th, 2018, 7:33 pm

For starters, use quotes around formula expressions:

Code: Select all

greater_than=$($henry_x-3)   #no
greater_than="$($henry_x-3)" #yes
Otherwise you'll run into trouble with + signs being interpreted by the preprocessor as string concatenation, and possibly other issues. That might or might not be the (only) cause of your problem.

You also don't need any of those [and] tags. By default, all listed conditions must match for the whole condition/filter to match. In this case, your code works exactly the same as if you didn't use [and] tags.

Post Reply