Time for action - writing a new scriptbind function in C++
In order to be able to execute C++ code from Lua, we need to write a new, so-called Scriptbind
function. Scriptbind
functions are functions that are exposed to Lua, which means that this C++ function can be called from our Lua script code.
Open the ScriptBind_Actor.h file. You will find all actor-related functions, which are accessible in Lua, as seen in the following screenshot:
If you scroll down, you can simply add a new function there.
So, let's add a new function and name it
TeleportTo
. Search for SetSearchBeam (which is the lastScriptbind
function in this file), and add your new function right under it in theScriptBind_Actor.h
file://teleport the actor to targetPos virtual int TeleportTo(IFunctionHandler* pH, Vec3 targetPos);
Note
A
Scriptbind
function always returns anint (number)
and gets an IFunctionHandler *pH as the first argument. Each following argument can be user defined. You can add as many arguments as you want...