Class cWorld; Function ScheduleTask; Only one Function Callback
#1
Hallo,

I want a ticker that calls a function every 5 minutes.
This is my Code.
Code:
function Initialize(Plugin)
  Plugin:SetName("MyPlugin")
  Plugin:SetVersion(1)
  local World = cRoot:Get():GetDefaultWorld()
  World:ScheduleTask(10, TaskFunction)
  return true
end

function TaskFunction(World)
  LOG(World:GetName())
end

But the Function TaskFunction is called only once.
Why this?
Reply
Thanks given by:
#2
Code:
function Initialize(Plugin)
    Plugin:SetName("MyPlugin")
    Plugin:SetVersion(1)
    local World = cRoot:Get():GetDefaultWorld()
    Callback = function(World)
        LOG(World:GetName())
        World:ScheduleTask(6000, Callback)
    end
    World:ScheduleTask(10, Callback)
    return true
end

This should work, had the same problem Wink

Edit: Sorry misunderstood your question.
You can not directly, add a function as parameter.
Reply
Thanks given by:
#3
The cWorld:ScheduleTask only schedules a function once. You have to reschedule it every time.
Reply
Thanks given by:
#4
(12-23-2014, 07:06 PM)STR_Warrior Wrote: The cWorld:ScheduleTask only schedules a function once. You have to reschedule it every time.
Well, i've only the Hook Option with HOOK_WORLD_TICK?
http://mc-server.xoft.cz/LuaAPI/OnWorldTick.html

Here my Example Code:
Code:
function Initialize(Plugin)
  Plugin:SetName("MyPlugin")
  Plugin:SetVersion(1)
  cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick)
  return true
end

function TaskFunction(World)
  LOG(World:GetName())
end

function OnTick(Time)
  local World = cRoot:Get():GetDefaultWorld()
  World:ScheduleTask(10,
    function()
      LOG("Execute")
    end
  )
end
Reply
Thanks given by:
#5
Or a Call the Function recursively.
Is that the best Option, realy?
Code:
function Initialize(Plugin)
  Plugin:SetName("MyPlugin")
  Plugin:SetVersion(1)
  local World = cRoot:Get():GetDefaultWorld()
  TaskFunction(World)
  return true
end

function TaskFunction(World)
  World:ScheduleTask(100, TaskFunction)
  LOG(World:GetName())
end
Reply
Thanks given by:
#6
You can use the example by Seadragon91
function Initialize(Plugin)
    Plugin:SetName("MyPlugin")
    Plugin:SetVersion(1)
    local World = cRoot:Get():GetDefaultWorld()
    Callback = function(World)
        LOG(World:GetName())
        World:ScheduleTask(6000, Callback)
    end
    World:ScheduleTask(10, Callback)
    return true
end

You can reschedule it in the function itself.
Reply
Thanks given by:
#7
Small problem here. Using a /reload will crash the server, if a scheduler task is started.
Reply
Thanks given by:
#8
(12-23-2014, 07:54 PM)Seadragon91 Wrote: Small problem here. Using a /reload will crash the server, if a scheduler task is started.

Right, the same problem I also have.
Reply
Thanks given by:
#9
The Problem here is, if the plugin is reloaded, is still a Schedule Task open. I can't close the running Task before the Plugin is reloaded.

How can i solve this Problem?
Reply
Thanks given by:
#10
It's a known bug in the server and requires changes to the lua/scheduler interface. The relevant issue is: https://github.com/mc-server/MCServer/issues/1556
Reply
Thanks given by:




Users browsing this thread: 2 Guest(s)