

The first thing we need is to reference the various bits of LWJGL we need to access var Sys = Java.type("") Not really much that needs explaining the interesting bits are in the script itself… ScriptEngine engine = manager.getEngineByName("nashorn") ScriptEngineManager manager = new ScriptEngineManager() While you probably wouldn’t want to write a whole game in Javascript, leaving some key resources and objects public and having a few hooks that evaluate custom scripts, is fairly trivial stuff considering the customisation potential you are handing your end users, its often the “modding” community that drives the extended sales of games especially in the indie arena.Īctually executing a script from Java is not a difficult exercise import javax.script.* This power also allows third parties greater accessibility, allowing people to “mod” a game while the core game remains unabused!Įmbedded scripting has come a very long way and accessing Java classes and methods from JavaScript couldn’t be easier, add to that the fact that Nashorn is several orders of magnitude faster than the previous engine, and you have a powerful combination. Scripting languages have a number of advantages they are great for quickly nailing together logic while some other component does the heavy lifting. Its rather useful to have a game “engine” that’s directed from a language like JavaScript.
