I'm currently looking into scripting languages that might be usable for games. JavaScript appears to be a good choice to me - from what I can tell, it has a small core, very large community, great variety of tools and libraries, CoffeeScript to replace some of JavaScripts quirks with quirks I prefer to live with... And it appears there are at least 2 decent options for using it for game scripting - either embedding v8 in a C++ application, or alternatively writing modules for node.js. Oh, and of course v8 is fast.

Given all that (and the fact that I dislike Luas quirks more so than those of JavaScript) - is there any reason you could come up with why JavaScript would not be suitable for game scripting?

Oh, and before anyone gets this wrong - of course I'm talking about more heavy-client games (I can't recall a better term right now), not about browser based games with WebGL or the like.

share|improve this question
1  
How it fares depends entirely on how it's used, what it's used for and who's using it. There's no correct answer to this question. What you're looking for is a discussion. See the FAQ to learn what types of questions to ask here and where to ask discussion questions like this one. – Byte56 Dec 29 '12 at 16:45
@Byte56 It wasn't really meant to spark discussions, but I'd agree that the question is poorly worded. I suppose I'll just try for now and come back here if I'm actually running into trouble. – Cubic Dec 29 '12 at 17:12
@Cubic From the FAQ: "If your motivation for asking the question is “I would like to participate in a discussion about ______”, then you should not be asking here." Discussions are really more suited for our chat, or for discussion forums. – Trevor Powell Dec 30 '12 at 22:04
@TrevorPowell As I've said in the comment before, starting a discussion was not the intent here. I only realized the question could be understood as a request for discussion after I'd already asked. – Cubic Jan 1 at 18:10
Whoops, I misread the comment. My mistake! – Trevor Powell Jan 1 at 18:48

closed as not constructive by bummzack, Tetrad Mar 8 at 17:10

As it currently stands, this question is not a good fit for our Q&A; format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

2 Answers

Javascript isn't designed for "heavy-client" games, it's more for web applications and making websites. If you don't like Lua, you could use Python, Ruby or even Perl. Heck, you could even use C# as a scripting language. Or if you're crazy, make your own scripting language with similar syntax to Javascript, just like the developers of Unity3d did. I cannot stress this more, if you want to use Javascript for desktop applications, don't, if you want to make web applications, feel free to use it.

I hope you a happy New Year.

share|improve this answer
1  
"Javascript isn't designed for "heavy-client" games, it's more for web applications and making websites" Please elaborate. Regarding speed and memory usage it seems to be about on par with Lua, definitely outperforming most Ruby implementations (and I'd suspect Python too). From what I can tell Unity3D uses JavaScript rather than something with "similar syntax to JavaScript". – Cubic Dec 29 '12 at 17:02
1  
It is much faster than Lua (assuming you aren't including LuaJit, which is the fastest scripting engine around that I know of), and lightyears betters than Ruby or Python (assuming you aren't including PyPy, but embedding PyPy as a script engine is not trivial from what I'm told). – Sean Middleditch Dec 29 '12 at 17:41
1  
SeanMiddleditch and Cubic hit the nail on the head. It can get really quick, just look at node. The whole speed argument is entirely moot: game scripts aren't supposed to do heavy math or physics - they are supposed to allow level editors to 'script' events in the level - it doesn't matter at all if you used the slowest language out there. A script might run once every, maybe, 50-100 frames: and that would just be it doing a little house keeping. Seriously scripting work should only run every few minutes. It's irrelevant that V8 Javascript can be fast, JS is perfect without it. – Jonathan Dickinson Dec 29 '12 at 19:05
I agree with Jonathan, you wouldn't create a high performance rendering engine in a scripting engine like in Lua or Python, I also want to note that transferring data from the native language(C++) to the scripting language will also impact the performance. – random Dec 30 '12 at 9:21
-1. Don't you consider your browser a client-side application? Don't you know you can easily run V8 on your computer (this is just what Node.js (a server-side JavaScript implementation) does)? – Yannbane Jan 20 at 13:14

It fairs as well as any other dynamic interpreted language.

The benefits you get are that it Just Works in the browser, JS debuggers are best of breed for scripting languages, and is quite a bit faster than almost every other language thanks to the browser arms race.

Problems you will run into is that it is dynamically typed, and hence has trouble being used to maintain large interconnected code base. Many easy to catch upfront errors in a static language will turn into crazy runtime errors (especially where non-numeric types are used with arithmetic operators). Code refactoring tools are practically nonexistent. Object model libraries exist but many are incompatible, making mixing some off the shelf components together very difficult.

My largest pet peeve with JS (and many other languages, including many statically typed ones) is that there is no way to define custom value types. In games, you use vectors a lot. I've often wondered if there are more vector variable/members in the average game than there are scalar values. The problem here is two-fold: creating new vectors requires heap allocations and creates GC pressure, which really does add up in real games to noticeable lag and pauses; you have to jump through hoops to have local pre-allocated vectors laying around for temporary values during calculations. The second problem is that conceptually you wan to treat vectors as value types, and you can and will end IP with a lot of goofy errors where you accidentally modify some vector argument rather than making a copy of it first.

Lastly, owning back to the GC and JS's design, there are many common JS features you just have to avoid using, which removes a lot of attractiveness of JS in the first place. The two biggest examples are anonymous closures (very common for the powerful functional style paradigm they allow in JS) as anonymous objects (used to pass arguments to fictions expecting many parameters or many optional parameters). Having use of those in your core logic can lead to a lot of GC pressure.

My end verdict would be to use JS if you're targeting the Web, because your only other real choice is Flash and that is dying out. If you do use JS, I recommend Chrome as your primary development browser and recommended browser for end users, but remember to test in other browsers you need to support often. The difference in performance for game-related code can be vast, and you don't want to find out last minute that your project only runs reasonably on Chrome.

share|improve this answer
This isn't for a browser game, rather I mean this as an alternative to Lua. Your point about low level operations is valid, but I was talking about using JavaScript as a scripting language for game logic rather than writing whole games in them. I'm probably going to cover most of my math needs with GLM. I don't think I'm going to run into performance problems (speed or GC related) with the usage pattern I have in mind. Thanks for information though, it helped. – Cubic Dec 29 '12 at 17:10
Indeed, I fail at reading comprehension. Sorry. – Sean Middleditch Dec 29 '12 at 17:40
-1. Scripting languages are usually dynamic and much more abstract... You wont be creating thousands of class instances in JavaScript, but don't worry: you could, as V8 is blazingly fast. And you can do OOP in JavaScript, if that's what you mean: forum.codecall.net/topic/73839-inheritance-in-javascript. – Yannbane Jan 20 at 13:17
I have done extensive game work in JavaScript. Of course it works, but it's not ideal. V8 is great, best there is for JavaScript, but all the problems I listed are real, production problems I had to work around, with V8 specifically. – Sean Middleditch Jan 25 at 22:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.