Jump to content




can you figure it out what is problem?



  • You cannot reply to this topic
7 replies to this topic

#1 hasunwoo

  • Members
  • 16 posts

Posted 22 June 2013 - 09: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???

#2 Tjakka5

  • Members
  • 256 posts

Posted 22 June 2013 - 09:18 AM

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

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

or

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


#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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)
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.


View PostTjakka5, on 22 June 2013 - 09:18 AM, said:

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 by theoriginalbit, 22 June 2013 - 09:32 AM.


#4 hasunwoo

  • Members
  • 16 posts

Posted 22 June 2013 - 09:36 AM

thanks;)

#5 Tjakka5

  • Members
  • 256 posts

Posted 22 June 2013 - 09:53 AM

View Posttheoriginalbit, on 22 June 2013 - 09:18 AM, said:

View PostTjakka5, on 22 June 2013 - 09:18 AM, said:

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.

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 June 2013 - 09:55 AM

View Posthasunwoo, on 22 June 2013 - 09:36 AM, said:

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?

View PostTjakka5, on 22 June 2013 - 09:53 AM, said:

-empty post-
Stop being a troll.

#7 hasunwoo

  • Members
  • 16 posts

Posted 22 June 2013 - 09:58 AM

i am first time with coroutine can you explaning coroutine with example program?

#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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