Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Author Topic: Yeaaah..  (Read 11043 times)

VBSmiles

  • Full Member
  • ***
  • Posts: 203
    • View Profile
Yeaaah..
« on: November 08, 2008, 11:43:45 pm »

Appearently this ASL stuff is rigged. Ok, maybe not. I just seem to be having a little problem with soaking in it as a programmer.


#command("object"); /*1*//* To start as menu item ? */
point3 $C_point;     /*2*//* current point */
float $dist;    /*6*//* Distance between points and ... */
 /*7*/   $model = project.curObject;



/* Get the marked point */
for $i = 0 to GetNumPoints($model)
{

 int $test = GetPointMarked($i);
if ($test = 1){
SetPoint ($i, $c_point.x, 0);
}
}

so uh.... what went wrong?
« Last Edit: November 09, 2008, 12:07:44 am by VBSmiles »
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Yeaaah..
« Reply #1 on: November 09, 2008, 05:33:44 am »

Hi VBSmiles,
one of the things that went wrong is the comparison you use in the if test. The boolean "is equal to" is "==", a single equal sign is used for assignation.

Another thing you missed is the "do" at the end of the "for" statement. Also you shouldn't be using functions such as "GetNumPoints()" as stand alone, it should be something like "$curshape.GetNumPoints()", where $curshape needs to be properly assigned with a new shape or an existing one, such as in:
$curshape = project.curObject.LookupShape("mesh01");

If you take a look at the Anim8or console while loading a script, some of the common mistakes are pointed out by the script parser.

Reading some already working script does help too, I've learnt a lot only by reading the scripts that NickE and Kubajzz shared on the forum.
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: Yeaaah..
« Reply #2 on: November 09, 2008, 07:09:05 am »

First, I recommend reading the ASL specification, it will help you a lot. As for your code, I've got several more notes:
Code: [Select]
$model = project.CurObject;
The "$model" variable is not declared in your code...

The "CurObject" function returns the current object, not the current shape. To select certain shape inside your object, use the "project.curObject.LookupShape(<<name>>);" function as Francesco suggested. You can also use "project.curObject.GetShapes(<<array>>);" to get an array of all shapes.

Code: [Select]
GetNumPoints($model)
Correct syntax is "$model.GetNumPoints();"


Oh, and Francesco is right, it really helps a lot to read the console output to find out what's wrong :) Good luck!
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2124
    • View Profile
Re: Yeaaah..
« Reply #3 on: November 11, 2008, 01:50:47 am »

Yu also need to be careful about upper and lower case names.  $C_point is not the same as $c_point
Logged

VBSmiles

  • Full Member
  • ***
  • Posts: 203
    • View Profile
Re: Yeaaah..
« Reply #4 on: November 12, 2008, 05:13:48 pm »

Thanks guys. I think I caught a few of the mistakes myself when I slowed down and studied ASL a little more closely. Also I am very well aquanted with VB ( hence the name ) rather than  than c++ so have forgotten some of the common differences in opperators and such  :P

theres some other differences I've yet to work out but will check out what you guys have stated.

( Steve )  ;D A common mistake of mine. Maybe I should use my VB compiler to code. It makes those fixes by itself. Just too lazy to load it onto the computer.
Logged

VBSmiles

  • Full Member
  • ***
  • Posts: 203
    • View Profile
Re: Yeaaah..
« Reply #5 on: November 12, 2008, 11:38:18 pm »

Sweet! got it to work!

Code: [Select]
/*************************************************/
/*** Script in progress made to flatten points ***/
/*** Created by: VBSmiles                              ***/
/*************************************************/
/*** declaration ***/
#command("object"); /*1*//* To start as menu item ? */
point3 $c_point;     /*2*//* current point */
float $dist;    /*6*//* Distance between points and ... */
shape $model;
int $test, $i, $NP;
file $file;
string $Output;

/*** Initialization ***/
$model = project.curObject.LookupShape("mesh01");
/*** Get the number of points in model ***/
if ($model != NULL)
{
$model.Open();

$NP = $model.GetNumPoints();

for $i = 0 to $NP do
 {
   $Output = PrintToString("%d", $NP);
   $file.open("$console", "w");
   $file.print("\n\n Value of $NP: " +$Output+ "\n\n");
   $Output = PrintToString("%d", $i);
   $file.print("\n\n Value of $i: " +$Output+ "\n\n");
   $file.close;

   /* Get the selected point */
   $test = $model.GetPointSelected($i);
   
   /*** if selected then store it's values ***/
   if ($test == 1)
      {
      $c_point = $model.GetPoint ($i);
      /*** reset it's x componenet to 0 ***/
      $c_point.y = 0;
      /*** move the point ***/
      $model.SetPoint ($i, $c_point);

      }
   }
$model.Close();
refresh();
} else
{
   $file.open("$console", "w");
   $file.print("\n\n where the hell is the model? \n\n");
$file.close;
}

Now I just have to figure out a better way  and add a way to choose axis  ;D
Logged