How to JavaScript

Hello guys and today i will teach all of you how to JavaScript. First we will be going over the basics of variables.

Variables
Ok let's talk about variables, First of all you need to think of a variable as box that holds a piece of information. And in JavaScript you call a variable "var" for short but always make sure that it is always a lowercase "v" and NOT uppercase. Now you can make a variable hold whatever information that you want for example the speed that you want your character to move for example you want your character to move at a speed at 10 which you would show like this in JavaScript,

var playerSpeed : int = 10;

Notice how i made the word "player" start with a lowercase letter as it is the first letter after the word "var" always remember to do that after the word "var" next we used a semi-colon becuase that says that "playerSpeed" is going to be whatever is after that semi-colon which in this case happens to be "int" which is basicly a whole number for example our player speed is "10" which is an interger which is longer for "int" however if you want to have your player moving or whatever at a point number for example "10.5" you would show it as a "float" like so,

var playerSpeed : float = 10.5;

Notice how i changed the word "int" with "float" because the number "10" is an "int" (interger) but our number is now a "float" which is a point number in this case it is "10.5" which is a "float" number.

Ok now, a variable can Also be a true or false value but we will get onto that in the next topic "Booleans".

Booleans
Ok now let's talk about booleans, a boolean is simply a true or false value. For example you still put a Boolean in a variable but it has a different meaning, for example you would use a true or falase value if you want to show that something is true or false. For expample, you want to tell Unity if you have clicked the "escape" button or not by doing the following,

var escapeButtonPressed : boolean = false;

Now notice how i put boolean after the semi-colon this time instead if "int" or "float" like in the last part variables because the peice of information is a true or false value. In this case it is a "false" value as you see when i put "false" in the example you could also change this to "true" that's if you wanted to tel Unity that you have clicked the escape button when you actually havn't yet.

"Please note that this script will not do anything if you copy and paste it into unity"

Ok students that concludes our Booleans topic for today in How to JavaScritp. In the next part we will be looking at "functions".

Functions
Ok functions, they are a default thing in Unity JavaScript that just appears when you create a new JavaScript. Usually it appears like this,


 * 1) pragma script

function Start {

}

function Update {

}

Ok, as you can see they are two functions and then just this funny looking orange text that says "#pragma script" and you can just delete this as you won't need it in anything. Now you also see "function Start" and you put anything that you want in this that you want to happen AS soon as the game starts and this is why it is called "start" function because whatever you put in this function will Only be called when you hit the play button. You would put things in here for example if yo were making a mini-game and you want a countdown timer to start as soon as the game starts as an example.

Now, the Update function that appears like this "function Update" you can put some more code in here that you want to happen anytime during the running of your game. now in example this could be the player movement script that you want to be able to happen anytime during your game.

Now, don't forget there are functions such as OnGUI which you make like rectangles in "Rect" (for short) and you can make inventory's and what not but i won't go over them just yet. in the next part we will go over "Printing".

Printing
Ok before you ask No when i say printing i DO NOT mean printing out some pretty pictures from your pc i mean printing in JavaScript. Now for example you can make a print after you have for exapmple clciked on a button that moves your character, you show it like this,

print("you are making the character move");

Now as you see what i typed it was something for example that you would put after your movement script when i say that i mean like right underneath it and call it in the same function that your character movement script is in for example when you click on a button you would see this print appear in the log at the bottom of your screen in Unity.

"Note this code will not do anything if you copy and paste into unity it was just an example unless you have a movement script then call this line of code after the movement code and then it should work"

Conclusion
Ok students and that was how to JavaScript now if you have any questions please DO NOT! hesitate to ask as you would be more than welcome to be answered by me :)

thankyou for listening,

-Bincredible