Page 1 of 1

{script} getDistance

Posted: Sun Sep 30, 2012 3:41 pm
by cromcrom
Hi all.
This script returns the direct number of squares between obj1 and obj2.

Code: Select all

function getDistance(obj1,obj2)
local distance = 0
local XNumber = math.max(obj1.x,obj2.x) - math.min(obj1.x,obj2.x)
local YNumber = math.max(obj1.y,obj2.y) - math.min(obj1.y,obj2.y)
distance = XNumber + YNumber
return distance
end
enjoy :-)

Re: {script} getDistance

Posted: Mon Oct 01, 2012 2:17 am
by Komag
that's a nice one, I like it! the closest thing to this in the original game was the dragon statues lining up thing, and I loved that one too. You could give clues to the player, compass headings, relative distance, etc

Re: {script} getDistance

Posted: Mon Oct 01, 2012 8:51 am
by cromcrom
Should it go to the useful scripts then ?

Re: {script} getDistance

Posted: Mon Oct 01, 2012 9:48 am
by petri
XNumber and YNumber should be local, otherwise they will be unnecessarily saved with save games.

Re: {script} getDistance

Posted: Mon Oct 01, 2012 10:15 am
by cromcrom
:oops:
Fixed, thanks :-)

Re: {script} getDistance

Posted: Mon Oct 01, 2012 12:09 pm
by Komag
yes, repository worthy!