Need help with javascript, it differs from the tutorial i am using.

I REALLY want to learn how to create video games but i have hit a wall just recently with the scripting aspect as i have searched and tried various tutorials but when created a java script they all seem to be extremely outdated or i am doing something very wrong.

My issues are:

  1. When i create a new javascript file; the file created differs from the file created in the tutorial vid.
  2. The script doesn’t seem to recognize certain words like “Log” of “Debug.Log” and “Axis” of “GetAxis” are not changing to the blue color of text while the others do. This is unlike in the tutorial video where everything goes very smoothly as to the text being recognized.

As a note, Here is the tutorial i am using.
http://www.youtube.com/watch?feature=player_embedded&v=6nH2VQRB-kQ#!

This is the code i have copied from the tutorial video.

1
2function Update () {
3
4 var horiz : float = Input.GetAxis(“Horizontal”);
**5 **
6 Debug.Log(horiz);
**7 **
8}

The file i get when i create a new javascript is:

1#pragma strict
2
3function Start () {
4
5}
6
7function Update () {
8
9}

Where as the file the guy gets in the tutorial is as simple as:

-function update() {
}

Why does the file i created just like in the tutorial vary so differently from the tutorial? Is it just outdated and the script has changed? What is going on with the text? What is up with the differences in the script files, is it something i did wrong and if so how do i fix it?

(I will be constantly checking back, all help is greatly appreciated! <3 :P)

What are you using for an editor? Although syntax coloring is purely cosmetic, and has no effect on functionality. In any case, GetAxis is one word; you wouldn’t have Axis be a separate color.

Yes. You can change the default script template if you want though.

No. It’s nothing to be concerned about.

–Eric

First of all, thank your very much Eric for taking the time out of your day to help me! I greatly appreciate it! :stuck_out_tongue:

  1. I am switching between UniSciTte and the default Monodevelop and trying both.

  2. What are the differences between the two “templates” and what is the better of the two to use in your opinion? What is the function start part and is it necessary to have for these simple scripts?

  3. How do i get the “Text color” to fully function and change just as in the video, even if it is just cosmetic, i would like it.

Again, thank you very much!

#2 - No template is really ‘better’ as they are provided as a shortcut so you don’t have to manually type that code in.
The ‘function Update()’ is generally used by most scripts - code in this function is executed each frame.
The ‘function Start()’ is also optional - this code is executed when your game starts, and is executed only once.
[Edit] Actually the Start() function is called whenever the game object is instantiated, not necessarily when the game starts. So you could destroy an enemy object, then re-add it again later, in this case it would be called twice.

If the tutorial video didn’t have the Start() function, it just means his template didn’t include it. If he wanted a Start() function, he could just type it in by hand.
Don’t worry about the template, if you don’t need either function it includes, you can’t just delete the text.

I would however recommend including the ‘# pragma strict’, because if this command is included in a script, it enforces proper variable declarations, and it avoids bugs (and run time errors perhaps) where your variable is instantiated as a different data type than you expected. You can code ‘more lazy’ with this command excluded, but you will run into bugs in the future where this simple command would have outlined your problem much earlier.

Thank you very much Slydog, i appreciate you spending your time to help me. Your user pic made me smile btw haha!

I think i have all the info i need now. Thank you all again.