Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Author Topic: Conditional Loops  (Read 2216 times)

user240485

  • Newbie
  • *
  • Posts: 4
    • View Profile
Conditional Loops
« on: April 26, 2010, 02:43:57 am »

Hello everyone I been using Anim8or for couple years now and I love it. Anyways I've been looking into ASL and trying my hand at a few scripts. First one i tried to do was a simple mirror script. It basically creates a mirror model across the X axis. And each time the script is run it locates the old model ("CopyMesh"), removes all old points, and updates the new points from the mesh that is to be copied ("mesh01"). Anyways what I cant do it seems is get conditional statements right. Im trying to make simple loops so it will load the points. I thought it was:

while (Condition) {Statement};

I really dont understand it I pretty sure that the correct format. If not please tell me. Every time i run my script the console tells me error ";" expected, error "}" expected, error "}" expected (Im sure its correct). Its my first script i have made and im racking my brains out trying to figure out why it wont work. (I know there is one under the topic EXPERIMENTAL MIRROR but that one is constantly running I just wanted it to update the mirror side ONCE at the push of a button, rather than selecting copy, deleting, selecting mesh, mirroring.)
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: Conditional Loops
« Reply #1 on: April 26, 2010, 03:29:24 am »

It would help if you showed a piece of your code...

It looks like you have a problem with basic ASL syntax (semicolons, block statements...). Here are a few rules to remember:
  • Every statement (variable declaration, assignment, function call etc.) must be ended with a semicolon
  • The curly brackets are used to create a compound statement - there can be zero or more statements between the brackets and the whole thing behaves like a single statement. There is not a semicolon after the closing curly bracket
  • There must be a matching closing bracket for every opening bracket
  • Compound statement can be used wherever a normal statement can be used

Here are a few examples (note: the code in these examples doesn't make much sense, it's only purpose is to show the proper syntax):

Code: [Select]
/* An empty loop */

while ($a == $b) { }

Code: [Select]
/* A loop with one statement in its body - the following examples are equal */

while ($a == $b)
  $number1 = sin($number2);

while ($a == $b) {
  $number1 = sin($number2);
}

Code: [Select]
/* A loop with more statements in its body */

while ($a == $b) {
  $number1 = sin($number2);
  $number3 = abs($number1);
  /* more statements can be here... */
}

Code: [Select]
/* WRONG CODE - semicolon missing after statement */

while ($a == $b) {
  $number1 = sin($number2)
}

Code: [Select]
/* WRONG CODE - an extra semicolon after the closing curly bracket */

while ($a == $b) {
  $number1 = sin($number2);
  $number3 = abs($number1);
  /* more statements can be here... */
};

The "if" statement syntax is pretty much the same btw.

I hope it helped...
Logged

user240485

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Conditional Loops
« Reply #2 on: April 26, 2010, 10:59:52 am »

Well I finally found out what it was. It turns out it had nothing to do with my coding of the statement at all. It seems it was really how i was writing the variables.

Apparently i cant write:
$num += 1;
but instead i have to write:
$num = $num+1;

I guess i have just been used to using += and ++ :P
I used to do some light coding for something else and gotten into the habit of shorting my code like that... Ah well thanks anyways.  :D

Below is a sample code that replicates the errors. All it does is count down from 10.
Code: [Select]
#command("object");

int $num;

$num = 10;

while ($num != 0)
{
    $num -= 1;
}
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: Conditional Loops
« Reply #3 on: April 27, 2010, 03:37:31 am »

Oh... Yeah, ASL is pretty much based on C but only a few C operators are supported... I'm glad you solved the problem. Good luck with your script!
Logged