This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hasunwoo's profile picture

can you figure it out what is problem?

Started by hasunwoo, 22 June 2013 - 08:07 AM
hasunwoo #1
Posted 22 June 2013 - 10:07 AM
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???
Tjakka5 #2
Posted 22 June 2013 - 10:18 AM
Ehm… firstly, this is the wrong section, and also:


local data = "hello"
print("" ..data)

or


local data = "hello"
print("hello")
theoriginalbit #3
Posted 22 June 2013 - 10: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)

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.


Ehm… firstly, this is the wrong section, and also:


local data = "hello"
print("" ..data)

or


local data = "hello"
print("hello")
Ummm what? o.O
Edited on 22 June 2013 - 08:32 AM
hasunwoo #4
Posted 22 June 2013 - 10:36 AM
thanks;)
Tjakka5 #5
Posted 22 June 2013 - 10:53 AM
Ehm… firstly, this is the wrong section, and also:


local data = "hello"
print("" ..data)

or


local data = "hello"
print("hello")
Ummm what? o.O

He had some code in OP that obviously wasnt working.
theoriginalbit #6
Posted 22 June 2013 - 10:55 AM
thanks;)
No problems :)/> Is this your first time working with coroutines? Do I need to explain what I did there, or can you work it out?

-empty post-
Stop being a troll.
hasunwoo #7
Posted 22 June 2013 - 10:58 AM
i am first time with coroutine can you explaning coroutine with example program?
Lyqyd #8
Posted 22 June 2013 - 03:21 PM
Moved to Ask a Pro.