variable or function expected

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 15:50, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   11 
Platform:   Windows  ;   
Language(s) :   C.O.F.F.E.E  ;

---------
I'm new to scripting in C4D and I just can't figure out what is wrong with my function definition.
If I paste the following code into the Script Manager and click Execute...

_TestFunction(msg)
{
 println(msg);
}

println("About to call the function");
TestFunction("This is the message");_

I get the error "[FAIL] Script 'TestScript' Line 1 Pos 14 : Variable or function expected."
It seems to happen with every function I try, even ones pasted from examples. Code by itself seems to work ok though.

e.g.

println("About to call the function");

by itself works just fine.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 16:28, xxxxxxxx wrote:

As far as I know, you can't call functions outside of another function (i.e.: globally) in COFFEE.  You usually start with main() and call other functions which call other functions or functions in class instances.

Every script starts with:

main(doc,op)
{
}

Every COFFEE plugin has a:

main()
{
}

Therefore, try something like this:

_TestFunction(msg)
{
 println(msg);
}

main (doc, op)
{
  println("About to call the function");
  TestFunction("This is the message");
}_

See if that succeeds! 🙂

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 16:57, xxxxxxxx wrote:

Thanks for your quick response kuroyume. I tried your code, but unfortunately I get exactly the same error. A friend of mine has just tried it in C4D V12 and he gets the same error as me. It's strange, it seems to reject any function definitions.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 17:00, xxxxxxxx wrote:

You have spaces within the main(doc , op) part that breaks it.
Try (works here) :

  
TestFunction(msg)   
{   
println(msg);   
}   
  
main(doc,op)   
{   
println("About to call the function");   
TestFunction("This is the message");   
}   

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 17:13, xxxxxxxx wrote:

You're right. The space in the main function before the bracket breaks it. Although the error message is not very helpful! 🙂

Thanks for your help.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 19:20, xxxxxxxx wrote:

That's pretty sad for COFFEE. 😞

Got Parser? 🙂