[[:articles:Game Scripting|<< Back to Game Scripting]] ====== jMonkey Engine Scripting ====== ===== Overview ===== This code is an attempt to add generic scripting to the [[http://www.jmonkeyengine.com/|jME]] project, through hooks into the GameConsole class, as well as creating Spatial controllers that are implemented through scripts. ===== Resources ===== * [[http://www.jmonkeyengine.com/|Java Monkey Engine Homepage]] * [[http://www.jmonkeyengine.com/wiki/doku.php?id=getting_started|Getting Starting with the Java Monkey Engine]] * [[http://www.jmonkeyengine.com/wiki/doku.php|jME Wiki]] * [[articles:Java Scripting Framework]] * [[http://code.google.com/p/jddaniels|JDDaniels project]] - The jME scripting framework was hosted here. (now it's hosted in the Captive Imagination SVN) * Captive Imagination SVN (http://captiveimagination.com/svn/public/cigame/trunk) * [[http://www.jmonkeyengine.com/jmeforum/index.php?topic=4761.0|GameConsole Forum Discussion]] - on the [[http://www.jmonkeyengine.com/jmeforum/|jMonkey Engine Forums]]. ===== Using the ScriptCommandProcessor and GameConsole in jME ===== By default the ScriptCommandProcessor will evaluate whatever text you enter in the scripting language set (By default Pnuts). You can register objects from your application to be available to the scripts by calling the register(string, obj). IE: GameConsole console = new GameConsole(KeyInput.KEY_GRAVE, rows, true); ScriptCommandProcessor scriptProcessor = new ScriptCommandProcessor(console); scriptProcessor.register("console", console); scriptProcessor.register("game", game); scriptProcessor.register("state", debug); scriptProcessor.register("box", box); The ScriptCommandProcessor provides the following highlevel commands commands: * Enter the script mode by typing "mode script" from the console * lang - Let's the user select a scripting language (IE: lang javascript - will change to javascript interpreter) * file - Evaluates the script file in your current working directory using the extension to determine the script language (IE: *.js, *.py, *.pnut, *.bsh) * addController - Adds a ScriptController to the spatial that was registered to the ScriptCommandProcessor.register() * removeController - Removes any ScriptController's from a spatial that was registered to the ScriptCommandProcessor.register() For example in the TestScriptConsole.java we register the box to the ScriptCommandProcessor: ... scriptProcessor.register("box", box); ... Then on the console we type: addController box spinController.js This will add a ScriptController implemented by the spinController.js file (It implements it by defining a "function update(time)" function): {{repo>http://jme-game-console.googlecode.com/svn/trunk/spinController.js}} Then to remove it the user can type in the console: removeController box {{articles:spincontroller.jpg|ScriptController screenshot}} ===== jME Scripting Implementation ===== ==== TestScriptConsole ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/test/test/TestScriptConsole.java}} ==== ScriptCommandProcessor ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/console/script/ScriptCommandProcessor.java}} ==== ScriptEvalCommandProcessor ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/console/script/ScriptEvalCommandProcessor.java}} ==== ScriptFileExecuteCommand ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/console/script/ScriptFileExecuteCommand.java}} ==== SetScriptLanguageCommand ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/console/script/SetScriptLanguageCommand.java}} ==== Script ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/script/Script.java}} ==== ScriptController ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/control/script/ScriptController.java}} ==== IScriptController ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/control/script/IScriptController.java}} ==== AttachScriptControllerCommand ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/console/script/AttachScriptControllerCommand.java}} ==== spinController.js ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/spinController.js}} ===== Modified Captive Imagination GameConsole ===== ==== GameConsole ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/console/GameConsole.java}} ==== CommandProcessor ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/src/com/captiveimagination/game/console/command/CommandProcessor.java}} ==== TestScriptController ==== {{repo>http://jme-game-console.googlecode.com/svn/trunk/test/test/TestScriptController.java}}