From 3ca2726ff9133025613f2146460b046052b75573 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 15 Dec 2017 16:54:43 +0000 Subject: [PATCH] Allowed the chaining of the on_event function --- locale/ExpCore/ranking.lua | 11 +++++------ locale/ExpCore/server.lua | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/locale/ExpCore/ranking.lua b/locale/ExpCore/ranking.lua index f3ecc4ac..561c44f8 100644 --- a/locale/ExpCore/ranking.lua +++ b/locale/ExpCore/ranking.lua @@ -220,16 +220,15 @@ function Ranking._rank:print(rtn,colour) end else -- using threads to make less lag - local thread = Server.new_thread{data={rank=self,rtn=rtn}} - thread:on_event('resolve',function(thread) + Server.new_thread{ + data={rank=self,rtn=rtn} + }:on_event('resolve',function(thread) return thread.data.rank:get_players(true) - end) - thread:on_event('success',function(thread,players) + end):on_event('success',function(thread,players) for _,player in pairs(players) do player_return(thread.data.rtn,colour,player) end - end) - thread:queue() + end):queue() end end diff --git a/locale/ExpCore/server.lua b/locale/ExpCore/server.lua index 1c541d93..4fb2b0dc 100644 --- a/locale/ExpCore/server.lua +++ b/locale/ExpCore/server.lua @@ -344,19 +344,17 @@ end -- if event is a number then it is asumed to be a game event -- @tparam string event the name of the event that it is called on -- @tparam function callback the function which is called on the event --- @treturn was the function added +-- @treturn table returns self so that there can be chained function Server._thread:on_event(event,callback) local events = {'close','timeout','tick','resolve','success','error'} local value = table.find(events,function(v,k,find) return v == string.lower(find) end,event) if value and is_type(callback,'function') then self['_'..value] = callback - return true elseif is_type(event,'number') and is_type(callback,'function') then if not self._events then self._events = {} end self._events[event] = callback - return true end - return false + return self end Event.register(defines.events.on_tick,function(event) @@ -405,4 +403,6 @@ return Server game.print('Events') end) thread:open() + + all on_event functions can be chained from the thread creation rather than use varibles ]] \ No newline at end of file