A visual roadmap of scripting?

Hello all, this is one of the first times I’ve ever posted here. I am sorry if this question doesn’t belong here, so please be kind, and let me know if I need to submit this question elsewhere.

Here goes: I think I am a visual learner. Does there exist anywhere a visual roadmap or chart of how classes, variables, etc, all fit together with javascript? I would like to see maybe an algorithm or flowchart of how, say, a Translate relates to other scripting components (sorry, I don’t have the vocabulary to speak well on scripting, that’s why I want to learn it better).

I am working my way through the Beginning 3d Game Development with Unity book and realized I don’t know how to make all these things fit together. I don’t know when something is capitalized, or, like this following example, why things are scripted the way they are:

(this is from page 380):

function OnMouseDown (){

if (animation) animation.Play(aniClip.name);

I understand a little of why CamelCase is used, and how it shows up in the Inspector, but how do I learn about the relationships between things like animation and Play (animation.Play)? Why so much (what appears to be) redundancy? How do I sort out the whole “animation.Play(aniClip.name)” ? Don’t get me wrong, I am learning a lot from this book, but I am still stumbling on the fundamentals.

If you had to teach someone the essentials of scripting, which direction would you point them in, to get them up and running the fastest?

Any help anyone can give is greatly appreciated.

Thanks,
Mike

3 Answers

3

What you need to learn is ‘object oriented programming’ and there’s tons of free stuff on the net.

In a quick nutshell:
Classes and Funtions get Capitalized
variables and members use camelCase
(these are just naming conventions we all use as good-practice, not required by the languages)
But unline HTML JS, case is vital. OnMouseDown is not the same as onMouseDown

A class is a collection of code and data (functions and members)
A class is defined as having these things.
An INSTANCE of a class is a variable whose type is a class.

Thus

class MyClass
{
  bool myBool;
  int MyFunc(int someVar);
}

myBool is a variable member of MyClass. MyFunc is a function member of MyClass.
You can’t do anything with it (unless it’s static) unless you make an instance of it:

myInstance = new MyClass(); // makes a variable of type 'MyClass'

Now you can access its members:

myInstance.myBool = true;
var newInt = myInstance.MyFunc(32);

Don’t use the same exact spelling and case for variables, so this would be bad:

MyClass MyClass; // what’s what?

Anyway, it’s much too big a subject for this forum, but I hope that little bit answers your immediate question.

Yea without a teacher it can be really hard to learn, ultimately in any book your going to run into points where they didn't write it in a way that makes sense to you so you need someone to explain it in a different way.

In general programming in Object Oriented Design. That means everything in your program is treated as an object and to be incredibly simple it basically results in hierarchy maps.

like this

http://www.google.com/imgres?q=class+hierarchy+diagram&um=1&hl=en&sa=N&biw=853&bih=414&tbm=isch&tbnid=6lUWG0fy2-5hUM:&imgrefurl=http://inkscape.org/doc/devdocs.php&docid=zurQG1vomJAM&w=843&h=505&ei=UiBQToGAL4mHsgKgmMjIBg&zoom=1&iact=hc&vpx=538&vpy=102&dur=378&hovh=95&hovw=158&tx=201&ty=91&page=1&tbnh=95&tbnw=158&start=0&ndsp=8&ved=1t:429,r:3,s:0

in there you can see the really big thing is called GObject at the top. its a class and each class has members, in this case its SPObject, SPEventContact, SPview & GTKObject

so when someone wrote the code what they wrote was this (roughly its pseudo code not real code)

class GObject
{
public members:

SPobject();
SPEventContact();
....
....
}

now to make this a little easier to understand instead of GObject, assume its a ball.

        class Ball

    {
    public members:

    SetRadius(x);
    myRadius();

   private members:
     radius;
    }

ball.SetRadius(x)
{
radius = x;
}

the way we would make a Ball in our program is first to declare a variable

Ball myPersonalBall;

now we've made a ball, MyPersonalBall is the name, Ball is what it is similar to if i was to declare you i'd write

human callmedata;

your a human, but there are many humans, i'm specifically talking about you.

now if i want to set a balls radius i write

myPersonalBall.setradius(10)

that sets the radius to 10 set radius is a member of myPersonalBall, more generally its a member of all balls, thats the point of a class. A class is a generic item, every human has a nose and every ball has a radius. Anytime you type

myPersonBall.setRadius(some number)

what your basically doing is saying earlier I defined what members balls have, done here.

        class Ball

    {
    public members:

    SetRadius(x);
    myRadius();

   private members:
     radius;
    }

now SetRadius just typing that doesnt do anything, its just some meaningless combination of words, if we want it to do something we have to define it, done here

ball.SetRadius(x)
{
radius = x;
}

now we've basically said anytime i type

myPersonalBall.SetRadius(10);

what i'm saying is, in my personal ball there is this member called SetRadius find that member, now i've defined that member and said what it does, it takes whatever number I put in parenthesis and makes it the radius. so go do that with the number 10.

now if we look at your line of code this is what we see

if (animation) animation.Play(aniClip.name);

your going to have to take some of this as true right now and learn why later but an easier way to view it is as multiple lines.

if (animation)
{
animation.Play(aniClip.name);
}

an if statement can only be true or false.

if true it does the stuff after it (the stuff in the brackets). if false it skips those lines of code and goes past it.

so that means if what is true? well if animation is true. that sounds odd but somewhere animation is defined as what's called a boolean value which is something that can only be true or false. what they probably do is something like

if we want to play an animation animation = true; if we dont want to play an animation animation = false;

then they test animation later on (in your line of code) to find out if they should play it

if they should (it's set to true)

do this

{
animation.Play(aniClip.name);
}

now from what you read and hopefully understood earlier we can see that

animation is class and it has a member called play, also aniClip is itself a class that has a member called name

the code they wrote should look like this.

class animation
{
public member:
play();
}

animation.play(theNameOfAnAnimation)
{
code for play, presumably it plays this animation but it wants you to tell it the name
}

class aniclip
{
public members
name();
}

aniclip.name()
{
code to return the name of the animation
}

so animation.Play(aniClip.name);

were calling the play member of animation, but just like when we called setRadius, myPersonalBall.setRadius(10) in that case we had to give it a number(10).

well in this case play requires a name, we know that it requires a name because clearly inside the parenthesis a name is being given to it so it must need it.

we get that name by looking at clip and calling its member name.

Not the best teacher hope that makes sense best of luck

now if we look at your line of code this is what we see
You wrote:

if (animation) animation.Play(aniClip.name);

your going to have to take some of this as true right now and learn why later but an easier way to view it is as multiple lines.

if (animation)
{
animation.Play(aniClip.name);
}

This is the kind of “side education” or backstory I need to be learning concurrent to learning how to script. These are the kinds of things I need to be learning. Otherwise, I am keeping up with what you both are telling me. I guess I just need to know that there is more than one way to skin the cat. What I didn’t realize was that what I initially thought was redundancy was actually just a way or paring down the scripting, making it leaner and more concise. This makes more sense to me now that you explain it this way.

Next, you wrote this:

{
animation.Play(aniClip.name);
}

now from what you read and hopefully understood earlier we can see that

animation is class and it has a member called play, also aniClip is itself a class that has a member called name

the code they wrote should look like this.

The way you explained it here makes some bit of sense to me. I guess I just need to know where to go to find out how to read between the lines. There seems to be a real gap in teaching these kind of fundamentals to a lay person like me. I am pursuing Unity as a serious hobby, as I am already a professional in another field which is totally unrelated to anything having to do with any of this programming language background (sorry, I know that sentence was very poorly constructed).

Any books or online resources you’d recommend to help a dolt like me get up to speed more quickly? Any fundamentals common to this kind of thought process, how to deal with problems in programming? Is ActionScript 3 really what I need to be learning? If so, can you recommend a book for a lay person?

Thank you both so much for spending the time to write such detailed replies. I genuinely appreciate the help.

Mike

Please respond to answers with comments. Also if you like an answer, choose it as The answer. Don't bother with ActionScript unless you are going to be doing Flex or Flash stuff. I mean, it's similar, but might just get in the way. IMHO programming is mixture of two things: recognizing patterns, and telling a story with math. Much too big a subject to go on about, and it's been so long since I learned the basics, I wouldn't know what's a good book out now, sorry. But there is tons of stuff, video, tutorials, etc. Best of luck.