Posted 21 February 2012 - 07:09 AM
Got a function that looks for events and logs them in a local variable outside of the function so that another function can use it. That other function is run WITH this function with parallel.waitForAny(). I use os.pullEventsRaw() to get my events. Here are the code pieces :
EVENTS
USING EVENTS
PARALLEL CALL
I get the error on the second loop in the mngrEvents function. The commented line was an attempt to correct the problem. With Casper's debugger, it says Variable: ev = timer then tells me that the code attempted to write to a global variable (title's the exact wording). If I uncomment ev = nil then the line stating the present value of the variable disappears.
I'll include the full backtrace file.[attachment=30:debugtraceback.txt]
EVENTS
function mngrEvents()
Events = {}
term.setCursorPos(1,1)
write('Events Manager online')
while true do
ev, p1, p2 = os.pullEventRaw()
table.insert(Events, {ev,p1,p2,false})
i = 1
while not(Events[i] == nil) do
if Events[i][4] then
table.remove(Events, i)
else
i = i + 1
end
end
--ev, p1, p2 = nil,nil,nil
end
end
USING EVENTS
function mngrKeyboard()
term.setCursorPos(1,2)
write('Keyboard Manager online')
while true do
i = 0
while not(Events[i] == nil) do
if Events[i][1] == "char" then
pcall(write(Events[i][2]))
fncMoveCursor()
Events[i][4] = true
end
i = i + 1
end
pcall(sleep(0.01))
end
end
PARALLEL CALL
parallel.waitForAny(
function()
mngrEvents()
end,
function()
mngrKeyboard()
end
)
I get the error on the second loop in the mngrEvents function. The commented line was an attempt to correct the problem. With Casper's debugger, it says Variable: ev = timer then tells me that the code attempted to write to a global variable (title's the exact wording). If I uncomment ev = nil then the line stating the present value of the variable disappears.
I'll include the full backtrace file.[attachment=30:debugtraceback.txt]