G'day there me beauties. "Hoorah!" I hear you cry, a new tut. But then you read the line that says "I'm going to teach you some code today". A deafening wail, a pounding fist, a small child crys. "Code? But I'm an artist - I don't need that geeky code type stuff. Bugger off!".
Ahh how little you know, you are but a child, lost in the wilderness of max, and know not of the wonder that is max script. Watch and learn young grasshopper, for your time is now.

Utter babble! But there is some truth in the above gibberish. Max script is a funky and groovy type addition to max, but it doesn't need a head the size of Stephen Hawkins' to understand it.

Hmmm, you don't llok convinced. But none the less I shall blunder on, in the vain hope that someone will find it useful.

The bunny just makes this scraping noise with it's good leg....


Lets start with how to get a script going shall we? got to the utility rollout and press the maxsript button (NOTE: you'll only have this button if you have V2.X) When you've pressed it you'll see something like this.....

This is the buisness end. Click "run script" and pick my script (which of course you've downloaded, your not going to get too far without it). This will fill the dropdown with the name of the script. You need to click on this to get it to run. But when you do (oh boy! I'm so exited) you'll get to see this fantastic peice of UI design....

To see the code you need to do an "open script" - go on do it now.....
A big window of gibberish will open - don't be scared it just code. Now the more observant of you will have noticed another thing. It's a window called this listener, and it looks like this......

Don't be affraid of it - the listener is you friend. It will help you find errors and test peices of code. Learn it, know it, love it.

The widget goes in the flibble - and then you wind it....


If you don't know diddley squat about programming - not to worry, your uncle chugg is here to put your wee mind at ease. But first a few basic things......
Your going to need to understand a few principals before you go off and code a utility that runs off a neural net and builds a mesh based on the thoughts your having in a past life (I'm not sure that would be possible, but you never know).

1.Variables

These are used ALL over the place, in fact you can't write any code without them. Think of them as a postcard. On the front is a name in big letters (a name you give it) and on the back is some info (a number or some text or something). In your program you'll need to know whats on these cards, so you look through yer big bag of variables looking for the one with the right name. When you find it, you can look at the back and learn it's glorious info contained there in.

For example....
we have created a variable called "Gibbon", and we want to fill it in with info and then print this info out...

gibbon = "The smell of cheese"
print gibbon

Now this is simple stuff here - it's not rocket science. There are several types of variable ie. "integer" "float" "string". These are ones you'll use all the time. Unlike many other languages maxsript doesn't need you to tell it what type of variable you need. You just pick a name and stuff a value in it, and maxscript understands.

2.Arrays

Oooooh! Programmer word. Don't frett, it's all ok. Think of an array as a chest of draws. It can have as many draws as you like, and in each draw is a variable. All the draw fronts have a number on them (starting at 1). When you want to know a variable in the array, you ask to look in one of the numbered draws. you setup your array like this...

Example 1.0
myarray = #()

This builds you a chest of draws called "myarray" and it, as yet, has no draws in it. If you want to put something in a draw you go...

Example 1.1
myarray[1] = "Something groovy"

This put the text "Something groovy" in the draw number 1. You can also create an array full of stuff to start with....

Example 1.2
myarray = #("a","b","c","d","e")

This will make an array with 5 draws all filled with a letter. Arrays grow with whatever you put in them. You can just keep adding draws and they get bigger.

Control, control, you must learn control...


OK son now for some flow control stuff. You have to be able to get your program to loop and make descisions and stuff by it's self. There are several ways to do this. A "for" statement loops round a bit of code x number of times. A bit like this..

Example 1.3
for i = 1 to 10 do
(
**some code stuff here**
)

This makes a loop that runs 10 times. It does whatever code you put inside the brackets. See? It's easy. If you want to do something based on a descision you need an "if" statement.

Example 1.4
if (variable here) == true do
(
**some code stuff here**
)

Now the astute among you will have noticed that there are two = signs in there. (Ha! bet you thought I'd made a mistake eh?) one = means assign to something (ie x = 10). but two = means "does it equal?". There are a few other combinations of these tests (they are called boolean operations)...

Example 1.5
< less than
<= grater than
> greater than
>= greater than or equal to
== equal to
!= not equal to

ok ok it's getti ng a bit dull now. I think we should get on to a bit of code type stuff. What we're going to write is an object renamer. With a few groovy features. Post fix, pre fix, enumerate (hmmm big word!) and replace. It should also teach you some valuable programmer type stuff. (but then again, it might not, you never can tell about these things)

Once more unto the breech dear friends, once more....


Sorry about all the wordy stuff this time folks. (not many pics in this one :o( ) Now all maxscripts that want to have buttons and things on the interface must look like this to start with....

Example 1.6
utility rename_utility "Renamer V1.0"
(
**utility code goes here**
)

the bit inbetween the brackets is where all the work is done. "rename_utility" is a variable, a big ole' one that hold the whole utility. The bit in quotes is what the util is called in the maxscript rollout. Now, we're going to need some boxes to enter text into, so we know what to rename our objects to. This bit is simple. Read and digest....

Example 1.7
group "Rename"
(
checkbox dorename "Use rename?"
edittext rename "Rename" enabled:false
edittext postfix "Post fix" enabled:false
edittext prefix "Pre fix" enabled:false
)

Now, I've put these controls in a "group" command. Nothing clever, it just puts a box round the controls on the pannel so they are easyer to see. The "rename" bit is the heading on the pannel for this group. All the controls that come inbetween the next set of brackets all appear in that group. The first control I added was a "checkbox" control. the "dorename" part is a variable name, and it's what the checkbox is refered to from now on. If you want to know if the checkbox is checked or not, you ask maxscript the state of the "dorename" checkbox like this, "dorename.checked". This is known as a property of the checkbox, and you use the . (dot) notation to get to it. A checkbox only realy has one property worth knowing and thats "checked". The next part of the checkbox command is the bit in quotes. This is the name that appears on the rollout. The next three commands are all the same, and they put a text input box on the rollout. They work in pretty much the same way as the checkbox command. First you use the "edittext" command, followed by a variable name to refer to it by and then some text to put on the rollout. This is then followed by a new bit. "enabled:false" is the status of the textbox and its been set to off. This means that the textbox will be greyed out (ie not active).

Before I go I just wanna say this....


Now learnig to code takes loads of time and effort. I'm not going to go in to all of it here, thats what the helps files are for. But look through my code and see if you can understand it. There are loads of comments to help you out (HINT: if you press CRTL-D in the code window it will colour the code into comments and commands) Try out some things,change the code and see what happens. See what makes it break and see if you can add some other features. There are just too many things to go into for me to be able to teach you script totaly. But this might just encourage you to give it a go.
If you make any good scripts then send em in :o)

Click this 'ere link to get yer 'aands on this script, for the disectin' arf.
Renamer Script