mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 13:01:39 +09:00
Allowed the chaining of the on_event function
This commit is contained in:
@@ -220,16 +220,15 @@ function Ranking._rank:print(rtn,colour)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- using threads to make less lag
|
-- using threads to make less lag
|
||||||
local thread = Server.new_thread{data={rank=self,rtn=rtn}}
|
Server.new_thread{
|
||||||
thread:on_event('resolve',function(thread)
|
data={rank=self,rtn=rtn}
|
||||||
|
}:on_event('resolve',function(thread)
|
||||||
return thread.data.rank:get_players(true)
|
return thread.data.rank:get_players(true)
|
||||||
end)
|
end):on_event('success',function(thread,players)
|
||||||
thread:on_event('success',function(thread,players)
|
|
||||||
for _,player in pairs(players) do
|
for _,player in pairs(players) do
|
||||||
player_return(thread.data.rtn,colour,player)
|
player_return(thread.data.rtn,colour,player)
|
||||||
end
|
end
|
||||||
end)
|
end):queue()
|
||||||
thread:queue()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -344,19 +344,17 @@ end
|
|||||||
-- if event is a number then it is asumed to be a game event
|
-- 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 string event the name of the event that it is called on
|
||||||
-- @tparam function callback the function which is called on the event
|
-- @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)
|
function Server._thread:on_event(event,callback)
|
||||||
local events = {'close','timeout','tick','resolve','success','error'}
|
local events = {'close','timeout','tick','resolve','success','error'}
|
||||||
local value = table.find(events,function(v,k,find) return v == string.lower(find) end,event)
|
local value = table.find(events,function(v,k,find) return v == string.lower(find) end,event)
|
||||||
if value and is_type(callback,'function') then
|
if value and is_type(callback,'function') then
|
||||||
self['_'..value] = callback
|
self['_'..value] = callback
|
||||||
return true
|
|
||||||
elseif is_type(event,'number') and is_type(callback,'function') then
|
elseif is_type(event,'number') and is_type(callback,'function') then
|
||||||
if not self._events then self._events = {} end
|
if not self._events then self._events = {} end
|
||||||
self._events[event] = callback
|
self._events[event] = callback
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
return false
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
Event.register(defines.events.on_tick,function(event)
|
Event.register(defines.events.on_tick,function(event)
|
||||||
@@ -405,4 +403,6 @@ return Server
|
|||||||
game.print('Events')
|
game.print('Events')
|
||||||
end)
|
end)
|
||||||
thread:open()
|
thread:open()
|
||||||
|
|
||||||
|
all on_event functions can be chained from the thread creation rather than use varibles
|
||||||
]]
|
]]
|
||||||
Reference in New Issue
Block a user