moveto event with "proximity check"
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.
moveto event with "proximity check"
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:
The coordinates are defined as follows:
Note: the -1 is deliberate, these are set later by an event.
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]
Code: Select all
{VARIABLE henry_x 56}
{VARIABLE henry_y 39}
{VARIABLE ashes_x -1}
{VARIABLE ashes_y -1}
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
Re: moveto event with "proximity check"
Is it intentional that you do not check anything about currently moved units location?
Re: moveto event with "proximity check"
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)
Re: moveto event with "proximity check"
Then you need to do the check after you update their coordinates.
Re: moveto event with "proximity check"
For starters, use quotes around formula expressions:
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.
Code: Select all
greater_than=$($henry_x-3) #no
greater_than="$($henry_x-3)" #yes
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.