whiteblXK
Active Member
Hello, for some time I have a problem with function addEvent, when I want to use it in the following way:
I have this error:
But when I use in this way:
I don't have any error.
How to use correctly first way in this function?
If the error is on the side of the source I put functions addEvent:
Code:
addEvent(doTeleportThing, 500, cid, pos)
I have this error:
Code:
callback parameter should be a function
But when I use in this way:
Code:
addEvent(function()
if isPlayer(cid) then
doTeleportThing(cid, pos)
end
end, 500, cid)
I don't have any error.
How to use correctly first way in this function?
If the error is on the side of the source I put functions addEvent:
Code:
int LuaScriptInterface::luaAddEvent(lua_State *L)
{
//addEvent(callback, delay, parameter)
ScriptEnviroment* env = getScriptEnv();
LuaScriptInterface* script_interface = env->getScriptInterface();
if(!script_interface){
reportError(__FUNCTION__, "No valid script interface!");
lua_pushnumber(L, LUA_ERROR);
return 1;
}
if(lua_isfunction(L, -3) == 0){
reportError(__FUNCTION__, "callback parameter should be a function.");
lua_pushnumber(L, LUA_ERROR);
return 1;
}
LuaTimerEventDesc eventDesc;
eventDesc.parameter = luaL_ref(L, LUA_REGISTRYINDEX);
uint32_t delay = popNumber(L);
if(delay < 100){
delay = 100;
}
eventDesc.function = luaL_ref(L, LUA_REGISTRYINDEX);
eventDesc.scriptId = env->getScriptId();
script_interface->m_lastEventTimerId++;
script_interface->m_timerEvents[script_interface->m_lastEventTimerId] = eventDesc;
g_game.addEvent(makeTask(delay, boost::bind(&LuaScriptInterface::executeTimerEvent, script_interface, script_interface->m_lastEventTimerId)));
lua_pushnumber(L, script_interface->m_lastEventTimerId);
return 1;
}
Last edited: