To create an embedded script, just create a new lua file with one function:
Code: Select all
function LayerScript(moho)
end
To actually attach the script, double-click the layer in the Layers window to bring up the Layer Settings dialog, and click the "Embedded script file" button.
Here are a couple samples: First, a script that adjusts the angle of a bone so that it always points downward, regardless of anything else going on with its parent bones or in the layer itself:
http://www.lostmarble.com/misc/hanging.zip
Notice that the script file remains an external file, just like an image or sound file used by Moho. In this example, the script looks for any bones named "Dangler" and adjusts their angles to point downward at all times.
Next example:
http://www.lostmarble.com/misc/targeting.zip
In this example, the script is attached to the "Scripted Group" layer. As the animation plays back, the script adjusts the angle of this layer so that it points towards another layer in the project, named "Target". No key frames are created in either of these scripts - instead, the scripts dynamically change the orientation of an object. So, if you changed the movement of the Target layer, the Scripted Group layer would automatically track the new position of the target.
(This second example could quite easily be modified to make the layer follow the movement of the camera instead of another layer.)