General Category > ASL Scripts
Requesting a simple controler script
Starbuck:
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
CobraSpectre:
Here's a visibility toggling script.
--- Code: ---int $length;int $offset;
$length = 24;
$offset = 3;
$visibility = !((frame-$offset)%$length);
--- End code ---
$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.
CobraSpectre:
Here's a version that you can set a starting frame.
--- Code: ---int $length;int $offset;int $startframe;
$length = 24;
$offset = 3;
$startframe = 48;
$visibility = (frame>=$startframe)&&!((frame-$offset)%$length);
--- End code ---
$startframe is the first frame of the object visibility animation.
Kubajzz:
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: ---(frame>=$startframe)&&!((frame-$offset)%$length)
--- End code ---
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: ---int $length, $offset, $startframe;
--- End code ---
just a detail, ignore it...
CobraSpectre:
I'll try my best to explain it. I started with Leslie's visibility controller examples.
$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.
Navigation
[0] Message Index
[#] Next page
Go to full version