moveto event with "proximity check"

The place to post your WML questions and answers.

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

moveto event with "proximity check"

Post by Anagkai »

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
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: moveto event with "proximity check"

Post by Ravana »

Is it intentional that you do not check anything about currently moved units location?
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Re: moveto event with "proximity check"

Post by Anagkai »

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
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: moveto event with "proximity check"

Post by Ravana »

Then you need to do the check after you update their coordinates.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: moveto event with "proximity check"

Post by zookeeper »

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