@@ -4,6 +4,7 @@ local event_sub = {}
44genv .temp = temp
55local url = ' http://127.0.0.1:4343/'
66local tasks = {}
7+ local filters = {}
78local ycounts = {}
89
910ws = http .websocket (url .. ' ws/' )
@@ -59,6 +60,7 @@ while true do
5960 elseif msg .action == ' drop' then
6061 for _ , task_id in ipairs (msg .task_ids ) do
6162 tasks [task_id ] = nil
63+ filters [task_id ] = nil
6264 ycounts [task_id ] = nil
6365 end
6466 elseif msg .action == ' sub' then
@@ -83,21 +85,29 @@ while true do
8385
8486 local del_tasks = {}
8587 for task_id in pairs (tasks ) do
86- local r = {coroutine.resume (tasks [task_id ], event , p1 , p2 , p3 , p4 , p5 )}
87- if coroutine.status (tasks [task_id ]) == ' dead' then
88- ws .send (textutils .serializeJSON {
89- action = ' task_result' ,
90- task_id = task_id ,
91- result = r ,
92- yields = ycounts [task_id ],
93- })
94- del_tasks [task_id ] = true
95- else
96- ycounts [task_id ] = ycounts [task_id ] + 1
88+ if filters [task_id ] == nil or filters [task_id ] == event then
89+ local r = {coroutine.resume (tasks [task_id ], event , p1 , p2 , p3 , p4 , p5 )}
90+ if coroutine.status (tasks [task_id ]) == ' dead' then
91+ ws .send (textutils .serializeJSON {
92+ action = ' task_result' ,
93+ task_id = task_id ,
94+ result = r ,
95+ yields = ycounts [task_id ],
96+ })
97+ del_tasks [task_id ] = true
98+ else
99+ if r [1 ] == true then
100+ filters [task_id ] = r [2 ]
101+ else
102+ filters [task_id ] = nil
103+ end
104+ ycounts [task_id ] = ycounts [task_id ] + 1
105+ end
97106 end
98107 end
99108 for task_id in pairs (del_tasks ) do
100109 tasks [task_id ] = nil
110+ filters [task_id ] = nil
101111 ycounts [task_id ] = nil
102112 end
103113end
0 commit comments