http://pastebin.com/sUSP3DJC
this program pulls the wired modem message and i can type message
but computer restarts after few second and i cannot type anything what is the problem with coroutine
and i wanna ask
local data = hello
print(hello)
it responds nil
but how can i convert text into string???
7 replies to this topic
#1
Posted 22 June 2013 - 09:07 AM
#2
Posted 22 June 2013 - 09:18 AM
Ehm... firstly, this is the wrong section, and also:
or
local data = "hello"
print("" ..data)
or
local data = "hello"
print("hello")
#3
Posted 22 June 2013 - 09:30 AM
As Thakka5 stated this is posted in the wrong section, please ask future questions in Ask a Pro.
Now the problem, the problem is that you only resume the coroutines once. The os.pullEvent is a wrapper for coroutine.yield, so you must resume the coroutines. Also your loop that "manages" the routines does not yield itself, so would also crash the program with a failure to yield.
A solution (only relevant code shown)
Ummm what? o.O
Now the problem, the problem is that you only resume the coroutines once. The os.pullEvent is a wrapper for coroutine.yield, so you must resume the coroutines. Also your loop that "manages" the routines does not yield itself, so would also crash the program with a failure to yield.
A solution (only relevant code shown)
function process()
local c1 = coroutine.create(chatreceive)
local c2 = coroutine.create(terminal)
local eventData = {}
while true do
--# resume our routine giving it the event data
coroutine.resume(c1, unpack(eventData))
if coroutine.status(c1) == "dead" then
c1 = coroutine.create(chatreceive)
end
--# resume our routine giving it the event data
coroutine.resume(c2, unpack(eventData))
if coroutine.status(c2) == "dead" then
c2 = coroutine.create(terminal)
end
eventData = { coroutine.yield() } --# you could also use os.pullEventRaw here, but again, it is just a wrapper of coroutine.yield, so why not just use the top level function
end
end
EDIT: Also it should be noted that if the read coroutine dies the screen will not be cleared, and the new coroutine does not remember the input from the old one.
Tjakka5, on 22 June 2013 - 09:18 AM, said:
Ehm... firstly, this is the wrong section, and also:
or
local data = "hello"
print("" ..data)
or
local data = "hello"
print("hello")
Edited by theoriginalbit, 22 June 2013 - 09:32 AM.
#4
Posted 22 June 2013 - 09:36 AM
thanks;)
#5
#7
Posted 22 June 2013 - 09:58 AM
i am first time with coroutine can you explaning coroutine with example program?
#8
Posted 22 June 2013 - 02:21 PM
Moved to Ask a Pro.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











