Function Newbie question...
kray at sonsothunder.com
Fri Dec 6 10:29:01 EST 2002
Actually, Malte, a repeat structure is exactly what you want, IMHO. You just
need to pass the references into your mouseUp handler. For example, suppose
you had 5 objects, and they were called "kreis1" through "kreis5". You could
do this in your mouseUp handler (I'm assuming a field to hold the results
repeat with x = 1 to 5
put item 1 of the loc of graphic ("kreis" & x) into x1
put item 2 of the loc of graphic ("kreis" & x) into y1
repeat with y = 1 to 5
-- Don't need to compare to itself, so skip when x=y
if x=y then next repeat
put item 1 of the loc of graphic ("kreis" & y) into x2
put item 2 of the loc of graphic ("kreis" & y) into y2
put getDistance(x1,y1,x2,y2) into tDist
put cr & "Distance from 'kreis" & x & "' to 'kreis" & \
y & "' = " & tDist after fld "resultfld"
This is off the top of my head, but it should work...
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
----- Original Message -----
From: "Malte Brill" <malte.brill at t-online.de>
To: <use-revolution at lists.runrev.com>
Sent: Friday, December 06, 2002 4:17 AM
Subject: Function Newbie question...
> Hi list,
> I wrote a small function that returns the distance between two Points.
> Function getDistance x1,y1,x2,y2
> put sqrt((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2) into theDistance
> return theDistance
> end getDistance
> It works for me if I pass the values to it on a mouseUp event.
> on mouseUp
> put item 1 of the loc of graphic "kreis1" into x1
> put item 1 of the loc of graphic "kreis2" into x2
> put item 2 of the loc of graphic "kreis1" into y1
> put item 2 of the loc of graphic "kreis2" into y2
> put getDistance (x1,y1,x2,y2)
> end mouseUp
> O.K., but if I have more than two objects (lets say about 5). how could I
> check the distances between all of them efficiantly?
> 1->2 2->1
> 1->3 2->3
> 1->4 2->4
> 1->5 2->5 ... 5->4
> Using a repeat structure seams not being a good idea to me. So here I am
> stuck, as the number of objects I want to check might vary from time to
> Any Ideas?
> use-revolution mailing list
> use-revolution at lists.runrev.com
More information about the Use-livecode