• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

addEvent error

whiteblXK

Active Member
Joined
Apr 20, 2011
Messages
315
Solutions
9
Reaction score
32
Location
Poland
Hello, for some time I have a problem with function addEvent, when I want to use it in the following way:
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:
Replace your code with this:
Code:
addEvent(function(cid, position)
    if not isPlayer(cid) then
        return false
    end
   
    doTeleportThing(cid, position)
end, 500, cid, pos)
 
My code works fine:
Code:
addEvent(function()
      if isPlayer(cid) then
               doTeleportThing(cid, pos)
       end
end, 500, cid)

This not working and I don't know why :/
Code:
addEvent(doTeleportThing, 500, cid, pos)
 
Use the first one though, much better. Else the server will complain and send you error notices if the player should die within the launch.

Ignazio
 
Code:
addEvent(doTeleportThing, 500, cid, pos)
This will either cause server crash or error. Due to it's not checking if the player is there.
 
Hmm, when I use this addEvent:
Code:
addEvent(test,2000,cid)

and function test:
Code:
function test(cid)  
    if isPlayer(cid) == 1 then   
        doPlayerSay(cid, 'Test', TALKTYPE_ORANGE_1) 
    end      
end
i have this error again :/ Why?
 
The error does not make any sense, try change function name and also don't use == 1 enough with isPlayer(cid) then
 
I change
Code:
isPlayer(cid) == 1
to
Code:
isPlayer(cid)
and I don't have error, and script works. lol

In this:
Code:
addEvent(doSendMagicEffect, 5000, getPlayerPosition(cid), CONST_ME_SOUND_YELLOW)

I have again this error, can you tell me how to fixt it?
Code:
luaAddEvent(). callback parameter should be a function.
 
Back
Top