Links

Creating‎ > ‎Scripting‎ > ‎

FAQ - Scripting

  • Why JavaScript?

    JavaScript is used to script game logic for the following reasons:

    • JavaScript is sandboxed: You can run JavaScript code from anywhere on the internet in a safe way (just like web browsers do with web pages). This lets the Syntensity client run all kinds of games. Also, a huge amount of effort has gone into the security of JavaScript engines, because of their use in web browsers. They are probably the most ubiquitous and tested way of running untrusted code.
    • JavaScript is a dynamic language: This was important to us, so the API lets you write concise code (which dynamic languages generally allow). Also, the flexibility of a dynamic language lets your game scripts completely customize each game (you can even change parts of the language and core API itself).
    • JavaScript has fast engines: Again, mostly due to their use in web browsers, some JavaScript engines have been made to run very fast (V8, TraceMonkey, Nitro, etc.). They are also getting faster all the time.

  • When I read from a StateArray or StateArrayFloat, I get 'undefined' values

    Due to limitations of the JavaScript language (regarding overloading the [] operator), you can't write things like

    this.myArray[2] = 55;
    var x = this.myArray[0];

    Instead, you should write

    this.myArray.set(2, 55);
    var x = this.myArray.get(0);

    However, it is perfectly fine to do:

    this.myArray = [20, 40, 80];
    var anArray = this.myArray.asArray(); // Returns an array version