// Error: Illegal operation on data of type string[]. //

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2003   #1
// Error: Illegal operation on data of type string[]. //

There has to be an easier way to convert data type[] to strings:

Here is part of my code:
//build cluster name
select $curselected[$i];
string $cluster_name = ($null_name + "_cluster");

// check to see if cluster already exists
$cluster_check = `listRelatives -c $null`;
for ($child in $cluster_check) {
if ($child == $cluster_name)
continue;
}

Here are my questions:
1 - so I am assuming that when you do a --for-- in -- operation on an array[] type that the value for each iteration is still an array?? why would this be? if you are iterating through each element in an array, in what scenario would it make sense that the data type stays of type array[]??

2 - Am I missing some sort of command like "ToString" to convert the data type?

3 - Basically I am trying to create a cluster under a null, but I want to check first to see if the cluster already exists... and if it does, to not proceed with creating the cluster(hence the "continue").... so I also wanted any input if there was a better way to do the pre-check. I was going to go with objExists but I may have the same named objects under different nulls and wasn't sure if that would work
 
Old 03 March 2003   #2
type that the value for each iteration is still an array??


No. Your array is a string array. Your named instance of it for that loop is a string. If it were still an array, you'd have to reference a specific index within the loop. As in...

if ($child[0] == $cluster_name);

When you loop over the array with "For-In," each instance of it ($child) is referenced for you of type string. This is what allows you to make a direct comparison between $child and $cluster_name. If they were of different types, you would get an error.

One thing that should help you (and is a good general practice that most MEL authors don't do) is to explicitly declare your variable types at the beginning of your script. Yes, it's more work and more lines of code. Yes, it helps you keep absolutely straight what the type of each variable is. Such as:

string $cluster_check[];
string $child;

$cluster_check = `listRelatives -c $null`;
for ($child in $cluster_check) {
if ($child == $cluster_name)
continue;
}

in the script above it is very clear that $cluster_check is an array while $child is a string. If you attempt to assign either a mismatched datatype, you'll get an error, alerting you to the problem.

-jl
 
Old 03 March 2003   #3
Thanks for the reply...

I did try the declarations at the beginning but I still was seeing problems and I think I may be doing something else wrong:

//build cluster name
select $curselected[$i];
string $cluster_name = ($null_name + "_cluster");
$clusterHandle_name = ($cluster_name + "Handle");

// check to see if cluster already exists
$cluster_check = `listRelatives -c $null`;
for ($child in $cluster_check) {
if ($child != $clusterHandle_name) {
cluster -n $cluster_name;

1 - I just realized that I was comparing against the cluster and not the cluster "Handle" which is what I should of been scanning for.

2 - Are there are issues with using the "!=" instead of the "==" with strings? I wouldn't think so.

3 - What happens when there are no children?? cause as this code stands it is not creating any clusters, ever, so the eval is always false... not sure what's happening there. Do you think that if there are no children that it skips the nested statement?

EDIT - OK - yes, because their were no children the cluster command was not being evaluated... so I had to wrap another if:

// check to see if cluster already exists
$cluster_check = `listRelatives -c $null`;
if (size($cluster_check) > 0) {
for ($child in $cluster_check) {
if ($child == $clusterHandle_name) { bla... bla... bla...

Last edited by tymznd : 03 March 2003 at 06:46 AM.
 
Old 03 March 2003   #4
Using == and != with strings appears to work in 4.5, however it's actually not documented to work that way. If you read the documentation on == and !=, it says that they are only guaranteed to work with integers, floats, and vectors.

The strcmp command is intended to compare the values of strings. strcmp returns different values depending on whether the strings are the same, or if different, which one comes earlier in the alphabet.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 01 January 2006   #5
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:14 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.