Game Development Reference
In-Depth Information
you saw earlier. This is just a simple wrapper to the ProcessManager::Attach-
Process() function:
void InternalScriptExports::AttachScriptProcess(
LuaPlus::LuaObject scriptProcess)
{
LuaPlus::LuaObject temp = scriptProcess.Lookup(
__object
);
if (!temp.IsNil())
{
shared_ptr<Process> pProcess(
static_cast<Process*>(temp.GetLightUserData()));
g_pApp->m_pGame->AttachProcess(pProcess);
}
else
{
GCC_ERROR(
Couldn
'
t find __object in script process
);
}
}
Let
s put all this together and see it in action with an example. This is a complete
process written entirely in Lua:
'
TestScriptProcess = class(ScriptProcess,
{
count = 0;
});
function TestScriptProcess:OnInit()
print(“OnInit()”);
end
function TestScriptProcess:OnUpdate(deltaMs)
self.count = self.count + 1;
print(
Count:
.. self.count);
if self.count >= 5 then
self:Succeed();
end
end
function TestScriptProcess:OnSuccess()
print(
Success!!
);
end
-- run some tests
parent = TestScriptProcess:Create({frequency = 1000});
Search WWH ::




Custom Search