I'm trying to write a macro that will calculate the distance between two cells on a map. It needs to use the "One_Two_One" metric to calculate this distance, so I thought I would use the GetDistanceToXY macro...but that assumes you are measuring from a token to a point on the map. I'm not; this is, effectively, always measuring from 0,0 to some determined set of coordinates.
Is there a way to do this that I'm not thinking of? That still keeps the "One_Two_One" metric I need?
GetDistanceToXY without source token
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: GetDistanceToXY without source token
Calculate the differences in X and Y direction, then take the smaller value, divide by 2 and add that to bigger distance. So, dX = 5, dY=2 total distance is 6 (dX + dY/2). Round down.
Not complete code, but guts of it.
Not complete code, but guts of it.
Code: Select all
<!-- gridDistance(point1, point2, isGrid) -->
[H: x1 = json.get(point1,"x")]
[H: y1 = json.get([point1,"y")]
[H: x2 = json.get(point2,"x")]
[H: y2 = json.get(point2,"y")]
[H: dArray = "[]"]
[H: dArray = json.append(dArray,abs(x1 - x2))]
[H: dArray = json.append(dArray,abs(y1 - y2))]
[H: dArray = json.sort(dArray,"d")]
[H: distance = json.get(dArray,0) + floor(json.get(dArray,1)/2)]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: GetDistanceToXY without source token
OMG, Alias, you da man! I'll give this a shot!