Skip to content

Basic Scripting

Thomas Cashman edited this page Sep 5, 2018 · 2 revisions

Now that you have miniscript added to your project, you can now set up your GameScriptingEngine.

Creating the GameScriptingEngine

First, create the GameScriptingEngine instance for your chosen scripting language.

Groovy

GameScriptingEngine scriptingEngine = new GroovyGameScriptingEngine();

Kotlin

GameScriptingEngine scriptingEngine = new KotlinGameScriptingEngine();

Lua

GameScriptingEngine scriptingEngine = new LuaGameScriptingEngine();

Python

GameScriptingEngine scriptingEngine = new PythonGameScriptingEngine();

Ruby

GameScriptingEngine scriptingEngine = new RubyGameScriptingEngine();

Updating the GameScriptingEngine

On every frame, you need to make sure to call the update(float) function of the GameScriptingEngine. The float value represents the amount of time that has passed since the last frame (often known as the delta).

scriptingEngine.update(delta);

Invoking a basic script

Before invoking a script, you need to establish the "bindings" of the script - that is, all the variables pre-established when the script runs. For now, let's not bind any objects and run a basic script.

Groovy

ScriptBindings scriptBindings = new ScriptBindings();
scriptingEngine.invokeScript("println \"Hello world!\"", scriptBindings);

Kotlin

ScriptBindings scriptBindings = new ScriptBindings();
scriptingEngine.invokeScript("print \"Hello world!\"", scriptBindings);

Lua

ScriptBindings scriptBindings = new ScriptBindings();
scriptingEngine.invokeScript("print(\"Hello World\")", scriptBindings);

Python

ScriptBindings scriptBindings = new ScriptBindings();
scriptingEngine.invokeScript("print \"Hello world!\"", scriptBindings);

Ruby

ScriptBindings scriptBindings = new ScriptBindings();
scriptingEngine.invokeScript("puts \"Hello world!\"", scriptBindings);

You've now successfully invoked a basic script through the GameScriptingEngine. It is now best to learn how the engine executes the scripts before moving on to more complex scripts.