Anim8or Community

General Category => ASL Scripts => Topic started by: Starbuck on April 24, 2008, 11:04:49 am

Title: Requesting a simple controler script
Post by: Starbuck on April 24, 2008, 11:04:49 am
Hey, I would realy appreciate it if someone could make a script for me.

I need a script that can control the visiblity of an object. I need it to be so that the object will be visible for one frame every second. And also so that you can choose the starting frame.

I need it so I can play a one second video continously.

Is this scrip possible to make?

I don't know the first thing about scripting. I need to learn. But for now I just need this one script.

Thanks
Title: Re: Requesting a simple controler script
Post by: CobraSpectre on April 24, 2008, 03:22:46 pm
Here's a visibility toggling script.

Code: [Select]
int $length;int $offset;
$length = 24;
$offset = 3;
$visibility = !((frame-$offset)%$length);

$length is the length of the cycle's animation.
$offset should be different for each object to determine its timing in the cycle, it should set from 0 to $length-1.

It needs to be put in the visibility expression controller obviously.

This runs continuously throughout the animation.
Title: Re: Requesting a simple controler script
Post by: CobraSpectre on April 24, 2008, 03:50:22 pm
Here's a version that you can set a starting frame.

Code: [Select]
int $length;int $offset;int $startframe;
$length = 24;
$offset = 3;
$startframe = 48;
$visibility = (frame>=$startframe)&&!((frame-$offset)%$length);

$startframe is the first frame of the object visibility animation.
Title: Re: Requesting a simple controler script
Post by: Kubajzz on April 24, 2008, 06:49:33 pm
Hey, CobraSpectre! I like that script... But I don't understand the last row of it ???

If I wrote this script, it would be 3 times as long and the result would be the same... it means there's something wrong with my scripts...
So... Could you please explain me, what this formula means (please keep in mind that my programming skills are... hm... not so good...):
Code: [Select]
(frame>=$startframe)&&!((frame-$offset)%$length)
btw. there's still one thing I would make shorter... You can declare more variables at once, I would make the first row like this:
Code: [Select]
int $length, $offset, $startframe;just a detail, ignore it...
Title: Re: Requesting a simple controler script
Post by: CobraSpectre on April 24, 2008, 07:20:23 pm
I'll try my best to explain it. I started with Leslie's visibility controller examples (http://www.biederman.net/leslie/tutorials/ASL%20Scripting/Visibility.htm).

$visibility works on 0, making it not visibile; and not 0 (usually 1), which makes it visible.

(frame%$length) is a modulo operation which finds the remainder of division, so when $length is 24 is will always output 0 to 23. So just this would make it invisible on frame 0, 24, 48...

The offset is subtracted (because adding didn't work  ;)) from the frame number to move which frame the action happens on.

The ! added on the front is a NOT, so that 0 becomes 1, and 1-23 become 0.

At this point, I wasn't sure if I could make it start at a particular frame number without an if statement. I looked at the scripting spec and found that the comparators return 0 or 1 based on truth.

(frame>=$startframe) gives 1 when the frame is greater then $startframe and 0 otherwise. && combines the two parts so that $visibility will be will be 1 when it is after the startframe and it is a frame it should be visible on.

I hope that's a good explanation, if I'm wrong, someone correct me.

Thanks for the tip on combining variable declarations.
Title: Re: Requesting a simple controler script
Post by: Kubajzz on April 24, 2008, 07:35:34 pm
Yes! I think I understand it... Thanks a lot!

Now I can see you've done a really good job on the script... and Leslie is a genious!

I would have used something like "if (fract(time)<=$Something) ..." The script would be very long and it would be pain to add "$length", "$StartFrame" and all that stuff...

Thank you once more for this little programming lesson :)
Title: Re: Requesting a simple controler script
Post by: Starbuck on April 25, 2008, 02:22:31 pm
That is perfect CobraSpectre :) :), You save me hours of work. I can't thankyou enough.

But can I bug you just one more time, can you make it so that you can deside how many frames it stays visible at a time. I need it to stay visible for 2 frames instead of one.
Title: Re: Requesting a simple controler script
Post by: Kubajzz on April 25, 2008, 03:28:28 pm
Here is my solution;

I hope CobraSpectre doesn't mind I edited his/her(?) script...

Code: [Select]
int $length, $offset, $startframe, $duration;
$length = 24;
$offset = 3;
$startframe = 10;
$duration = 2;
$visibility = (frame>=$startframe)&&($duration>((frame-$offset)%$length));

Cheers ;)