Notifications
Clear all

[Closed] dumb question

hey guys!
I’m having a very serious problem:
(I do not have a clue of what I am doing btw)
when i write this lines:

g=3;
if (g<4) then print “test”;

I will get this in return:

3
“test”
“test”
OK

now my question:
why is it that I get the “test” two times? am I dumb? I don’t have an idea…
thx, georg

4 Replies

Hi,

In MXS, everything is an expression that returns something just like LISP. MXS always returns the last line of a code/fn when evaluated. So the second “test” is the result of that. To prove this, evaluate this:

		 				g=3;

if (g<4) then print “test”
OK

Light

at first i’d like to thank you for your reply but I still don’t get it.
when I evaluate these 3 lines:
g=3;
if (g<4) then print “test”
OK

I get as result:

3
“test”
“test”
OK
OK

so I guess I get the “result” additionally to each line of code?

1 Reply
(@jeff_hanna)
Joined: 11 months ago

Posts: 0

Use format() instead of print() and you won’t get the second echo’d response.


local g = 3  --no need for a trailing semi-colon in MAXScript
if g < 4 then format "%
" "test"  --prints "test" to the listener and goes to the next line.

If you have the avguard extensions (avg_dlx##.dlx) then you can use formattedPrint()


local g = 3
sTest = test
if g < 4 then formattedPrint sTest
else()

Sorry,

Sometimes I post a code here without parenthesis. But I always intend to say run the code in local scope, that should take the problem out.

Try these:

(
g=3;
if (g<4) then print “test”
OK
)– 1 time

(
g=3;
if (g<4) then print “test”
)– 2 times

Light