Three 'How do I...?' with user scripts

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

arfa
Posts: 244
Joined: Tue Dec 23, 2008 8:15 pm
Location: New Zealand

Three 'How do I...?' with user scripts

Post by arfa »

I have been picking my way through Macton's "Here's some handy scripts" and have a few questions.

________________
Crash Core:
cc_shift_layer_keyframes.lua
"shift any or all the generic layer keyframes in either the currently selected layer or for the complete document. A positive number shifts right, a negative number shifts left."

This sounds tantalisingly like time insertion. Only thing, it throws up an error :(
attempts to index local 'layer' (a nil value)
Does anyone have any experience with this script? Is it for an earlier version of Moho?
*aside*: I got a copy of JS_key_all.lua which seemed to suggest key selection (single layer). Anyone know about this one?

__________
Genete:
ge_freeze_points
Stumped at the fist step...
1) Embed the script (freezerx.lua or freezery.lua) into the desired vector layer.
How does one 'embed' script into a layer?

______________
Rylander:
DR_two_way_ticket_frame0 -- Got this working fine. But,
what got me looking was the need to insert 'holding' keys.
Frame 22 - twiddle this and that, hold still until frame 66 - then more twiddle. So, I need to go back to frame 22 to copy the keys then to 66 to paste them. It seems that memory is flushed on clicking the 'go back' button. Ditto jumping (shift right arrow) to the end of the animation, ditto keying in the frame number on the timeline. Often the jump is back to frame 0 to get an 'original' set of keys - then back to frame 'x'. The only way I have to date is, an often tedious, 'drag the timeline pointer.' Is there some way to get back to frame 'x' - with either frame 0 keys still selected or, held in memory?

Comments on one or all welcome.

Spring is almost here and play time will be less. Oh well.

thanks - arfa
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Genete:
ge_freeze_points
Stumped at the fist step...
1) Embed the script (freezerx.lua or freezery.lua) into the desired vector layer.
How does one 'embed' script into a layer?
From here:
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.
-G
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 5:29 pm
Location: Sunny Florida
Contact:

Re: Three 'How do I...?' with user scripts

Post by mkelley »

arfa wrote: *aside*: I got a copy of JS_key_all.lua which seemed to suggest key selection (single layer). Anyone know about this one?
The purpose of this script is to *create* keys for any type layer -- it is supposed to key all (hence the name), rotation, translation, etc. It doesn't select any keys.

(For some reason I had to rewrite this script to work like I wanted it to, but right at the moment I couldn't tell you why. I do know that my version is the one I use but that doesn't necessarily mean JS's version doesn't work).
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

From my experience many of the Crashcore/Macton scripts are... "fragile". Sometimes they worked sometimes not so much. Many of them often crash AS for me. I have also noticed spelling or syntax errors in some of the Macton scripts. Very tricky to find in these scripts due to their size and complexity.

Keep in mind that these scripts were created YEARS ago for Moho, not AS. There may be a new version of lua in the current AS or there may have been subtle changes to the scripting access.

I had similar problems with a set of scripts for copying and pasting bones. The creator of these scripts used a very complex structure to make large tables or lists of things like keys and bones. Along with this is the pop up dialog box for checking of properties to copy.

In this case the error seems to be caused by one of the check box selected options. You may want to experiment with those options to find the right combination that allows the script to run.

I got the script to run on a test document with a single bone on a bone layer and a vector layer with point motion keys. I selected "Apply starting with current layer" at the top. I unchecked ALL the other boxes. Then I checked the vector layer "AnimPos" check box and the bone layer "AnimAngle".

Start with something VERY SIMPLE FIRST. Try it on a complex document but only check a few boxes at first to see where the issue might be.

Keep in mind that keys key frame interpolation WILL NOT be mainatained when moving keys with this script. They keys are NOT being "moved". They are being COPIED and then PASTED to a new location. The keys interpolation will default to "linear".

Key frame interpolation unfortunately is not available in the script reference of AS. You can't "get" a keys interpolation.

The error you describe refers to the variable that defines the layer selected (or... ANY layer of the whole document during the looping move keys part of the script). For some reason that variable is not being defined, or maybe it was defined and something else is happening.

Because of the complexity of their scripts it's been hard (for me at least) to figure out exactly where the errors are being caused. I do use them sometimes for reference for my own scripts (especially pop up box design).

I spent ages reverse engineering the copy/save layer animation and copy/paste bone scripts and still never quite understood exactly what was going on. I got the basic idea of what they were doing but it was very "deep" and much of it was either over my head or unnecessarily complex. I eventually had to simplify it and do my own thing.

-vern
arfa
Posts: 244
Joined: Tue Dec 23, 2008 8:15 pm
Location: New Zealand

Post by arfa »

________
Genete:
Thanks for the pointer - and the script. I have it working just fine. Really useful.
Am I right that it only freezes +x -- as per your example of the squashed ball? Not -x. I had imagined that an 'x' freeze would be total - no left or right. Ditto y-freeze.
_______
Vern:
Yes, I too was regularly thinking as you say "YEARS ago". Environments change. This thing with not being able to 'get' key data seems a limitation. I guess this is only within Lua. There is a lot for me to polish and an easy way to (help with) adjusting timing would be a great boon. Overall, I am moving quite cautiously with adopting 'the NEW SUPER! script' but for sure there does seem to be a lot of potential with Lua.

I have found a few gems in that collection that are proving useful. I really liked being able to go through the "vovanimation" *.moho examples and get a feel for how someone else puts a file together.

*repeat*
Is there some way to get back to frame 'x' - with either frame 0 keys still selected or, still held in memory?

- arfa
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

arfa wrote:This thing with not being able to 'get' key data seems a limitation. I guess this is only within Lua.
No, no limits really with lua. Lua is POWERFUL as it is. Even the "older" version in AS has AMAZING POWER to do anything you can think of. The "key interpolation" missing from the scripting interface is something that the creator of AS has to put in. None of the scripting we use to access parts of the AS file directly are part of lua. They were added by the developer of AS, Mike Clifton. He created a "library" of methods and functions and properties of elements in AS that can then work with lua compiled in the AS application.

Lua itself has nothing to do with AS. It is an open source programming language like Actionscript or Javascript that is compiled inside other applications. For instance some applications have Javascript support (Flash for instance). Javascript is open source. The people running that project could care less about anyone's specific applications.

Lua is used predominately in game creation because it is very fast and very powerful and takes up so little space in the application. Each game engine designer has to create their own way to communicate with lua and then back to the game.

The application developer must create "hooks" or whatever in their own application that then communicates with lua inside the application. If the developer for AS did not add or create a way to access the key interpolation then there is no way for us to get it or use it using lua. Once that "hook" is added in then we can "get" the value and use lua to do things with those values.

The scripting interface in AS is fantastic, but to get access to more of the interface or elements poor Mike has to do that for us. ;)

-vern
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

I've been looking at Macton's shift layer keyframes, and it looks like it could be 'fixed' pretty easy. The only problem I see with it is that it doesn't work for 'current layer only'. Well it also didn't bother to mark the document as dirty.

I think this script works well for adding time. If anyone's interested, I could do these fixes. The only thing I don't really like is that it changes all of the keyframe interpolations to linear. Isn't there a way to access the default interpolation? Vern? If so, I rather change it to use this.

If not, I'd probably prefer to change this to smooth interpolation. Or with more work, I may be convinced to make it an option, but that might take longer than I really want to work on it. :wink:
arfa
Posts: 244
Joined: Tue Dec 23, 2008 8:15 pm
Location: New Zealand

Post by arfa »

script works well for adding time. If anyone's interested,
I like to imagine that as I get better at planning my timing will be more precise but even pre-As, with flash and games, I always seem to think of something extra. Or, need to add more time - usually add.

SO... Yes p l e a s e.

whooooo - could this be the 'add time' I covet?

araf
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

I'll post it as soon as I get it fixed. Like I said, I'm going to change it so that the moved keyframes are smooth interpolation instead of linear. I may eventually make that an option, but I don't really want to spend that much time on it right now.

:wink:
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

http://www.mediafire.com/?ftmetdmdtgy

Here you go, Arfa! Please put this through its paces and let me know if it has any other big problems. The original script would only move layer manipulation keyframes when you selected 'Only apply to selected layer'. Now it will move all the applicable keyframes. This is why it didn't seem to be working for that option. Also it was just a small problem that gave that error you were seeing. It's all fixed now.


Like I said before, any moved keyframes will be given smooth interpolation. If you use linear or something else as your usual interpolation, I can change that easy enough, but like Vern said earlier, there's no way to maintain a variety of interpolations while doing this.

I hope this helps, let me know if it works out.



:wink:
User avatar
Víctor Paredes
Site Admin
Posts: 5818
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

thank for this script, it's pretty useful and works just fine. thanks
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Good job Synth! Every time I look at Macton scripts I get dizzy and sleepy. ;)

-vern
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

:lol: I probably wouldn't have bothered, but that error Arfa provided gave me a handle on it. I've only used that script a few times and never had any trouble. But after seeing all the trouble Arfa was having adding time, I felt someone needed to do something.

Kind of the rule around here, I figure. The most diligent get the most help.


:wink:
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

heyvern wrote:From my experience many of the Crashcore/Macton scripts are... "fragile".
How he tells me :-)

I am using the cc_load_camera/Save_camera script. The latest problem is ASP thins all imported keys are linear, not smooth (which is the ASP default). No hint in the cc_script. Might have to mod this script to include key data (assuming it is possible to script that data).

Rhoel
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

http://www.mediafire.com/?ywwrxomntwm

Here's cc_load_camera_animation with smooth interpolation keyframes. No way to preserve a variety of interpolations, but the default should be better. :D
Post Reply