Simple Guide To AS Scripting Dream?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Simple Guide To AS Scripting Dream?

Post by DK »

I'm probably dreaming but here goes.....

I heard people like vern in the past saying he taught himself how to code and I see people having a go at it in various threads. I'm pretty familiar with coding action script and a couple other areas but Lua just leaves me stumped.

Just wondering if one of the scripters would be generous enough to possibly find some time to do a simple AS scripting guide?....maybe something like taking a very simple script example and pointing out where the code needs to be placed in a script (using different colour fonts)and what that code affects?

I think if there was a more base level understanding of AS Lua scrpting that more people would contribute to the forum.


Cheers
D.K
jonbo
Posts: 896
Joined: Thu Apr 08, 2010 2:53 am

Post by jonbo »

Hey DK, I don't know if you've seen Gilles's blog on script explanation. It's pretty much a break down of a simple script and quite easy to get your head around. Here's the link:

http://gcharb2d.blogspot.com/2011/08/sc ... asics.html

also check this thread:
viewtopic.php?t=3065
User avatar
hayasidist
Posts: 3848
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Post by hayasidist »

Gilles has an entry level tutorial. http://gcharb2d.blogspot.com/2011/08/sc ... asics.html.

If you know any procedural / object-based language then it's not that hard to pick up LUA. the hard part (well it was - and still is an ongoing task - for me) was to get to understand the LM / moho data structures and functions (or whatever it is that they're properly called).

The thread viewtopic.php?t=13513 gives some basic documentation for AS 6. It has changed for 7 and 8 but this is a good basis. also look at other scripts for inspiration.

it really depends on where, programming skills-wise, you're starting from. If you need to learn to write computer programs then that's one challenge - but if you're already a proficient programmer but just lack LUA / moho skills then that's a different challenge.

do you have a specific scripting idea in mind?

(oh - and jonbo's also pointed out Gilles' blog in the time it's taken me to type this!)
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

WOW!!!! Thanks so much for that Gilles and hayasidist, jonbo for pointing it out. It's all clear to me finally. :lol:

Though I don'y have a scripting idea in mind just yet everyone should read that blog just to see how much work there is in writing an AS script. Makes us apprectiate the time and effort the scripters on the forum put into them.

Things like having to re-address the curvature on each pont in the circle after they have been welded in that example is eye opening. But the tutorial is wonderfully broken down and a real credit to Gilles. Thank you mate.

Cheers
D.K
User avatar
GCharb
Posts: 2274
Joined: Mon Oct 10, 2005 2:31 am
Location: Montreal, Quebec, Canada
Contact:

Post by GCharb »

Glad I could be of service DK.
User avatar
hayasidist
Posts: 3848
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Post by hayasidist »

once you get the hang of what you're doing, it's really quite quick to write code ... about as time consuming as a long email about some academic subject where you have to choose your words very carefully and put your ideas down in a very well-ordered structure. What slows me down is having to reach for the "dictionary" (the LM scripting interface documentation / the LUA math library function calls ...) at just about every turn. Now I'm getting a better understanding of what's in there, the search for the right function is faster and less frequent. It's just another learning curve...

If you want to try something and need help ... well ... this (or the other place) is the place to be. I've said it before and there's no real harm in repeating it - I'd been lurking on this forum for about a year before I got my log-on and plucked up courage to post something. I was amazed at the friendly, helpful, patient attitude of the "masters" towards us noobs... (spammers excluded! :lol: ) I'm barely out of diapers in terms of what I know about AS but ... I've gained a lot, directly and indirectly, from lurking and being here, so I'm glad to put a little of what I do know back into this society ...
User avatar
GCharb
Posts: 2274
Joined: Mon Oct 10, 2005 2:31 am
Location: Montreal, Quebec, Canada
Contact:

Post by GCharb »

I am starting to work on a more advanced scripting tutorial today, one on tool scripting, with menu and check-box, mouse and keyboard events etc.

Should be interesting, will try to put it up for monday!
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Well....I just had a thought for a script that would be quite handy but I don't know how hard it would be to create.....

In Lightwave there is a plugin called "BANG". What it does is take an object and splice it up into pieces and puts them onto seperate layers that can be then animated for an explosion.
Not sure if theres anything like this in AS already but I could've sure used it the other day simply to break a shape into smaller objects to animate it crumbling away.

I imagine to write this script you would somehow have to count and store all points in the shape, store colour and outline data. Then add more random points into the shape and re-connect the points in a manner that maintained the original shape, add original colour and line data. Then copy each object to the same number of layers as per existing shapes.

Would that be a close approximation to the process?


Having an expert scripter break these steps into Lua code would be quite interesting to see here.


Cheers
D.K
User avatar
GCharb
Posts: 2274
Joined: Mon Oct 10, 2005 2:31 am
Location: Montreal, Quebec, Canada
Contact:

Post by GCharb »

In ASP 8 there is the break apart shape in the script menu that does something similar, that is if I understood what you want properly.

Just finished my second script for my next scripting tutorial.

Will be a lengthy, intermediate level tutorial with tons of, I hope, useful infos.
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

GCharb.
Thanks for that. I was totally unaware of it...but for the life of me I can't seem to get it to work at all???

Cheers
DK
User avatar
GCharb
Posts: 2274
Joined: Mon Oct 10, 2005 2:31 am
Location: Montreal, Quebec, Canada
Contact:

Post by GCharb »

You need to assign a different shape for the parts you want broken up, then you select the shapes then run the script.

Here is a sample file for 8.

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

You got the original layer with a star with 6 different fill in it, then a group layer with all the broken shapes.
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Aaaahhh! OOPs

EDIT: You are right! Thats what I meant! But I cannot get the script to run as per your sample????

D.K
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Sorry GCharb....I am not understanding this.......does this script take the star shape and break it up by itself? Or do you have to break the starshape up into bits then run the script?


If it is the latter...I cannot get the script to break up a shape into smaller bits?????

D.K
User avatar
GCharb
Posts: 2274
Joined: Mon Oct 10, 2005 2:31 am
Location: Montreal, Quebec, Canada
Contact:

Post by GCharb »

I made another sample file where the star different shapes are colored.

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

The script break apart the shape based on the different shape it has.

In this example I gave every shape that makes the star a different color to show you how this works.
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi GCharb.
I understand now how the script works thanks but...it is not what I was refferring to in the original post. I was thinking of a script that will take 1 solid shape and break it into pieces and place them on seperate layers.

This script would be a good starting point for a new script that automatically broke a solid shape up into seperate smaller pieces I imagine.

Cheers
D.K
Post Reply