Works as js file in browser, but not Unity

Hey everyone,

So I’ve been working on some code on my breaks at work and wanted to plug it into Unity. Trouble is, when I try it out by typing it into notepad, saving it as “.js” then running it on IE (again, work computer), and the code works fine. Then I try running it in Unity and it gets an error.

Here’s how I have it in Unity:

function Start () { 
//Core Stat - these will determine the overall abilities of a character.
var coreStats={
str : 0,         //Strength
agl : 0,         //Agility
int : 0,         //Intelligence
per : 0,         //Personality
prc : 0,         //Perception
end : 0,         //Endurance
wil : 0,         //Willpower
lck : 0          //Luck
};
}

And I get told that str and the others are an unknown identifier.

in my .js i have it written:

<!DOCTYPE html>
<html>
<body>
<script>
var coreStats={
str : 0,         //Strength
agl : 0,         //Agility
int : 0,         //Intelligence
per : 0,         //Personality
prc : 0,         //Perception
end : 0,         //Endurance
wil : 0,         //Willpower
lck : 0          //Luck
};
</script>
</body>
</html>

and it works fine.
What am I not doing or doing wrong here?
Thanks!

EDIT: Oh, I should also mention that I forgot Unity already uses “int” and have already changed it.

Unity does not use Javascript at all. It’s technically called Unityscript, and is very different from web Javascript and not compatible with it. If you want to write something outside of Unity that’s fairly similar to Unityscript, use ActionScript3 in Flash instead of Javascript (it’s possible to write ActionScript3 code that compiles with few if any changes in Unity). Anyway it looks like you want to use a class.

class Stats {
    var str : int;
    var agl : int;
    // etc.
}

–Eric

Ahk, really?! Well this does suck, I’ve been spending two weeks learning javascript and writing in it…

Oh well, a few changes here and there and I’m sure I can manage.

Thanks again Eric!