Mel keeps throwing an error when I try to print the value of a variable

I have a simple scene consisting of curve1 and curve2, I have both of them selected.

I want to query my selection and save it $selection and then print $selection, just to confirm if it worked:

string $selection[] = `ls -selection`;
$selection[0];
$selection[1];

But the script editor errors out with:

// Error: $selection[0];
// Error: Line 2.14: Syntax error
// Error: $selection[1];
// Error: Line 3.14: Syntax error

I tried swapping things around or removing the trailing ; just for the variable lines:

string $selection[] = `ls -selection`;
$selection[0]
$selection[1]

I just end up getting a similar error

When I run all three lines I am expecting to get some kind of confirmation of what is contained in $selection.
For example by just running ls -selection;, I get an output of:

// Result: curve1 curve2

Does $selection actually have a value at all? or am I just not printing it right?

PS: I know this is probably easier with Python but I am specifically learning Mel.
Thanks for any help.

Unlike Python, MEL doesn’t print variables if you execute them on their own line. You just need to add print ($selecttion[0]) etc.

1 Like

That did it, I completely looked over that function. Thanks!