What is the difference between 'assignment' and 'equality' operators

What is the difference between 'assignment' and 'equality' operators

dvgbaokar
Contributor Contributor
569 Views
2 Replies
Message 1 of 3

What is the difference between 'assignment' and 'equality' operators

dvgbaokar
Contributor
Contributor

HI

Learning max script with help of "Script help documentation"

In FAQ s came across this question 

"What is the difference between 'assignment' and 'equality' operators'

While evaluating in listener and editor both codes give same result

not throwing any error in the first case when " if a = 0 " is written instead of " a ==0"

TYPICAL ERROR:

   a = 1
   if a = 0 then print "A is Zero!" else print "A is not Zero!"
   -- Type error: if-test requires BooleanClass, got: 0

CORRET CODE:

   a = 1
   if a == 0 then print "A is Zero!" else print "A is not Zero!"
   -->"A is not Zero!"
0 Likes
570 Views
2 Replies
Replies (2)
Message 2 of 3

MartinBeh
Advisor
Advisor

1.) a = 0 is an assignment in MAXScript, i.e. "store the value 0 in the variable a"

2.) a == 0 is an equality comparison, i.e. "check whether a contains the value zero"

 

But you are right!

 

MAXScript no longer complains about

 

     if a=0 then ( ... )

 

You can also simply write

 

     0==false

 

and get "true" as result, without an error

 

Not sure when this was changed! It used to throw an error, but now it seems to do the same many other programming languages do:

It will use "0" as equivalent to "false"...

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 3 of 3

istan
Advisor
Advisor

Fortunately you must not write now (a === b) 😁

0 Likes