Isotropix Forums

printf - how to use it - errors

Discuss about expressions in Clarisse

printf - how to use it - errors

Unread postby atnreg » Thu Feb 07, 2019 3:27 pm

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!

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA RTX 3090,Win10
UE5,Clarisse 5.0(always latest SP),Houdini,Blender,ZBrush,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 599
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: printf - how to use it - errors

Unread postby dcourtois » Thu Feb 07, 2019 4:54 pm

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:

1.
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:
printf("foo")


2.
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 = ... ;'
printf("foo");


3.
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:
42

# 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.

Regards,
Damien.
User avatar
dcourtois
 
Posts: 129
Joined: Tue Jul 25, 2017 3:15 pm

Re: printf - how to use it - errors

Unread postby atnreg » Thu Feb 07, 2019 5:43 pm

Hi!

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!

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA RTX 3090,Win10
UE5,Clarisse 5.0(always latest SP),Houdini,Blender,ZBrush,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 599
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland


Return to Expressions