Re: conditionals

jon klein <[email protected]> Mon, 16 May 2005 09:28:35 -0400
Newsgroups gmane.comp.breve
Message-ID <[email protected]>
On May 14, 2005, at 1:51 PM, Cavan Fyans wrote:

> hi,
>
> can anyone help me out here....in the code (linked at the bottom) im
> trying to run a conditional (if) statement in the iterate method of
> 'Indicator'.  I have been trying for a while now and cannot get it to
> compare vectors to the desired result.  All i want to do is compare
> 'loc' (a vector) the location of the object with another vector (9.5,
> 2, 1) and when the object moves past this point for it to stop moving
> the iterat emethod is as follows:
>
> + to iterate:
>             loc = self get-location.
>             if loc > (9.5, 2, 1): self set-velocity to (0, 0, 0).
>             #print loc.


The issue is that "greater than" and "less than" aren't defined for
vectors.  Vectors have 3 coordinates, so you have to be a little more
specific about what you're comparing.

The most likely scenario is that you want to test the length of the
vector -- to see if an object is more than a certain distance away
(in any direction).  You get the length of the vector with | vector |,
and then compare that to a float:

if | loc | > 20.0: ...

The other alternative is that you want to compare just one coordinate
of the vector to see if the location is past a certain line.  For
example, if you want to see if the agent has crossed an invisible
line at X = 20:

if loc::x > 20.0: ...


- jon klein
_______________________________________________
breve mailing list
[email protected]
http://lists.spiderland.org/mailman/listinfo/breve