Posted 14 April 2015 - 08:42 PM
while experimenting with coroutines and handling event loss during peripheral calls I am having an odd issue, if I try and use peripheral call on an openperipheral peripheral inside a coroutine, (I understand the entire comutercraft system runs on coroutines and thats what makes this odd) it triggers an internal error.
This is how I reproduced the error I was having:
I would just like some feedback as to whether this is my misuse of coroutines or a real issue
[20:31:27] [Coroutine-258/INFO] [OpenMods]: Unwrapped error during method getPlayers(9) execution on peripheral openperipheral_sensor, args: []
java.lang.ArrayIndexOutOfBoundsException
This is how I reproduced the error I was having:
openpsensor = peripheral.wrap("top")
remote_computer = peripheral.wrap("computer_1")
--module
function sensor_reader()
while true do
--standard peripheral is fine
print(remote_computer.getID())
--internal error here
status, value = pcall(openpsensor.getPlayers)
if status == true then
print(textutils.serialize(value))
else
print(value)
end
coroutine.yield()
end
end
--state
local modules = { ["next_pid"] = 1, ["routines"] = {}, ["event_router"] = {}, ["events"] = {} }
function modules.add(func)
modules.routines[modules.next_pid] = coroutine.create(func)
modules.next_pid = modules.next_pid + 1
end
--Kernel
function process()
while true do
for i,v in ipairs(modules.routines) do
coroutine.resume(v)
end
--openperipheral works here
status, value = pcall(openpsensor.getPlayers)
if status == true then
print(textutils.serialize(value))
else
print(value)
end
os.pullEvent("tick")
end
end
function event_distribute()
while true do
local event = {os.pullEvent()}
end
end
function ticker()
while true do
os.queueEvent("tick")
os.sleep(0.05)
end
end
--startup
modules.add(sensor_reader)
parallel.waitForAny(process, event_distribute, ticker)
I would just like some feedback as to whether this is my misuse of coroutines or a real issue