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);