PDA

View Full Version : Array related


Tåke
11-25-2003, 07:54 AM
string $objects[] = sort(`ls -sl -l`);
string $objects[] = `ls -sl -l`;

If I use one of these arrays in my code, it works nicely.
But, if I try using an if command to switch between the making of the array, I just get a bunch of errors.
I've tried declaring the array almost everywhere in the script, but it wont work.
It seems like maya wants to process the info below my if command before anything else!!
How can it be solved?

The sketchy code:
if ($sortobj == 1) {
string $objects[] = sort(`ls -sl -l`);
}
else {
string $objects[] = `ls -sl -l`;
}

dwalden74
11-25-2003, 09:18 AM
You'll probably want to declare the $objects[] string array outside of the {}. Otherwise it won't be visible to anything else.

Try this:

int $sortobj = 1;
string $objects[];

if ($sortobj == 1) {
$objects = sort(`ls -sl -l`);
}
else {
$objects = `ls -sl -l`;
}

for ($o in $objects)
print ($o + "\n");


Seems to work.

Tåke
11-25-2003, 10:21 AM
I had declared it, but I wrote my code with too many brackets
string $objects[];
$objects[] = sort(`ls -sl -l`);

instead of
string $objects[];
$objects = sort(`ls -sl -l`);

Thanks again!!

CGTalk Moderation
01-16-2006, 07:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.