Notifications
Clear all

[Closed] Strange results from a simple if statement?

Hi all

I am very new to maxscript and am receiving really wierd results from a simple if statement, I cannot understand what I am doing wrong so forgive me if this may seem trivial to you.

What I am doing is generating a random amount of faces, some that are perpendicular to the z-axis and others that are not. Problem is, at random intervals the statement returns false when in actual fact it should be returning true. This is happening even if all face normals are exactly the same.

        for i=1 to faceNum do
        (
            p = polyOp.getFaceNormal $ i 
            if p == [0, 0, 1] then
            (
                print "true"
            )
            else
            (
                print "false"
            )
         )

At the moment p = [0,0,1] at every increment of i and yet I am still getting falses every now and again. What am I doing wrong?

Thanks in advance
Luca

4 Replies

According to the help the direction returned is the current coordinate system, so what coordinate system are you working in?

-Eric

Thanks for the speedy reply Pixel_monkey.

Well I havent specified node so I would pressume it is the poly’s local co-ordinate system that I am working in. What confuses me is that for every instance that I print ‘p’ ( about 500 times) it returns constantly a value equal to [0,0,1] and yet it returns random false statements when in effect that should never be happening.

Hi, it’s not a problem with the ‘if’, it’s a precision and display problem. For example you can do this in the listener:


   f = 1.000001 
   1.0
   p = [0,0,f]
   [0,0,1]
   p == [0,0,1]
   false
   

Check out Bobo’s answers to this thread for a good explanation

aaahhh, thanks so much for the help dr. I really appreciate it.