Page 1 of 1

printf - how to use it - errors

Unread postPosted: Thu Feb 07, 2019 3:27 pm
by atnreg
Hi again!

I tried to use the printf function but I cannot get it to work :o

The simple test from manual:
Code: Select all
printf(“Hello world”); # with only this line and no ; there are no errors but nothing gets to log either
1 # this is needed as printf does not return anything, same errors with and without this

Gives error message:
Expression bound on project://scene/exprtest/box_r.translate[1] failed to compile:
Line 1 Col 21 - Syntax error at line 1 near ';':
printf("Hello World");

What am I doing wrong? :)

Thank you!


Re: printf - how to use it - errors

Unread postPosted: Thu Feb 07, 2019 4:54 pm
by dcourtois
Hi Antti,

The printf function doesn't seem to work. SeExpr outputs its content to stderr, and in Clarisse we just don't display those. We might have to override the native printf SeExpr function to allow printing to the log, but for now it won't work.

As a side node (related to the comments in your code snippet:

In a SeExpr expression, you have 2 distinct parts: the first part where you declare variables. Each line of this part must end with a comma (;)
and the last part, which is the last statement of the expression, and doesn't end with a comma. This last part is what's used as the result of the expression.

So, in your example, here is what happens:

Code: Select all
# printf returns 0. It's not documented, even in the official SeExpr site (I had to dig in the code to see that)
# So this line gets evaluated to 0, and the expression is valid and has a value of 0:

Code: Select all
# Now, if you add a ; at the end, the line becomes a variable definition, and you have a syntax error
# since variables should be defined like this : 'var_name = ... ;'

Code: Select all
# To fix the previous error, you just have to make it so that it's a valid variable def:
a = printf("foo");

# now the previous line compiles. And we still need a last statement so that the expression has a value:

# or you could just write:
# a
# Since a is a valid variable, which has the value 0 (remember, printf returns 0 in fact)

We'll have to improve our documentation a bit, and in the meantime I hope this explanation answers a few of your questions.


Re: printf - how to use it - errors

Unread postPosted: Thu Feb 07, 2019 5:43 pm
by atnreg

Thank you, that makes perfect sense, too bad Disney has done so bad work in documentation :o
The printf or log or whatever function would be useful for 'debugging' the expressions :)

BTW, was the '42' just random or was it intentionally THE answer? If you didn't understand what I just meant, then it was just accidental ;)

And please, do no other fixes before the light shadow fix, it is the most important now :mrgreen:

Thank you!