Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / MEL / Problem with variables (possibly) changing types.
  RSS 2.0 ATOM  

Problem with variables (possibly) changing types.
Rate this thread
 
39630
 
Permlink of this thread  
avatar
  • Dorian
  • Posted: 10 February 2010 07:17 AM
  • Total Posts: 3
  • Joined: 10 October 2009 08:57 PM

So I wrote a simple script to rotate a bunch of objects at random angles. For reference here it is:

// Script for setting the rotation of a group of objects at random angles.
// Author(s): Dorian Patterson
// License: Public Domain, or least restrictive open source license available.
// Short explanation: This script requires that all the object be labelled in post numerical order. i.e. pCube1, pCube2, pCube3, ..., pCube#, where # is the nth version of the object.
// $max = Maximum number of items to rotate. Substitute with appropriate value.
int $max 10;
for(int $i 1$i <= $max$i++)
{
 
// $prefix = the prefix for the object to rotate. In this example for a default polygon cube, it's pCube.
 
$prefix "pSphere";
 
// $name = name of the current object to rotate. It will be appended by the current count number $i.
 
$name $prefix $i;
 
// Selects the object.
 
select $name;
 
// Starts a new seed with the current count value.
 // Generates random values between 0 and 360. These are floating point numbers.
 
$rotX rand(360)
 $rotY 
rand(360)
 $rotZ 
rand(360)
 
// Finally the most important function, rotates the object with the set values.
 
rotate $rotX $rotY $rotZ;
};

When I first use it in a scene, it works fine. I can reuse it multiple times over and over. Everything is hunky-dory.

The problem comes after reloading the scene. The first time this happened, I got errors about using an incompatible operator on a string. For some reason $max was being interpreted as a string. I tried renaming the variable, implicitly declaring its type as int, but none of that worked. Restarting Maya did.

Now, it complains about a syntax error. Again, restarting Maya solves the problem, but that is a stupid workaround. Am I missing a simple fix, or is Maya just a pain in the -insert body part here-?
Thanks for any help!



Replies: 0
avatar
  • THNKR
  • Posted: 10 February 2010 11:36 AM

int $max 10;
int $i;
for 
($i 1$i <= $max$i++)
{
 
// $prefix = the prefix for the object to rotate. In this example for a default polygon cube, it's pCube.
 
$prefix "pSphere";
 
// $name = name of the current object to rotate. It will be appended by the current count number $i.
 
$name $prefix $i;
 
// Selects the object.
 
select $name;
 
// Starts a new seed with the current count value.
 // Generates random values between 0 and 360. These are floating point numbers.
 
$rotX rand(360)
 $rotY 
rand(360)
 $rotZ 
rand(360)
 
// Finally the most important function, rotates the object with the set values.
 
rotate $rotX $rotY $rotZ;
}


Replies: 0
avatar
  • Dorian
  • Posted: 05 May 2010 02:42 PM

Thanks for the reformat. Does anyone know anything about this, though?



Replies: 0