View Full Version : Adding elements to an array

06 June 2007, 05:23 AM
I've been looking around and looking around and I don't know if mel has the power to do this or not.

I'm trying to simply replicate a standard assigning element's values in an array, eg -

string $varList[2];
string $varList[0]={"blarg"};
string $varList[1]={"garlb"};

But instead of adding to the array it simply declares the array again so the above script would simply be -

$varList size = 1 and $varList print = garlb

For further knowledge to anyone reading this, I'm trying to proccess out math before entering a for loop, finding magnitudes of verticies and I would like to simply call them up in the for loop I have set. I know this can be done in c++, I know it can be done in java, hell this can even be done in php, but does mel have a way of adding elemenets to an array?

06 June 2007, 06:37 AM
Since you're putting "string" in front of the variable on each line, it is redeclaring it. So to do what you have written it should look like this:

string $varList[];
$varList[0] = "blarg";
$varList[1] = "garlb";

You don't need the braces either, because it will think you are giving it an array (and not just one element).

If you know the index you want, this works fine. Otherwise there are commands like "appendStringArray" and "stringArrayCatenate" where you can append and combine arrays. They're both in the help docs.


06 June 2007, 06:55 AM
thanks stev

06 June 2007, 07:26 AM
is there a stringArrayInsertAtIndex but for vector arrays? I tried "vectorArrayInsertAtIndex" but that doesn't exist hehe.

CGTalk Moderation
06 June 2007, 07:26 AM
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.