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

Process not being detected

Started by cdel, 06 March 2015 - 12:11 PM
cdel #1
Posted 06 March 2015 - 01:11 PM
I am creating a small multitasking system, I am clearly creating the process with the new() function, however when I use the run() function it claims that the process doesn't exist. My code is as follows:

local tArgs = {...}
local process = { }
local proc = { }
local er = function(text)
  error(shell.getRunningProgram()..": "..text, 0)
end
local new = function(name, func, dVa)
  if type(name) == "string" then
    if type(func) == "function" then
	  if type(dVa) == "table" then
	    process[name] = { }
	    process[name]["Pr"] = coroutine.create(func)
	    process[name]["Di"] = window.create(term.native(), dVa[1], dVa[2], dVa[3], dVa[4], dVa[5])
	    table.insert(proc, name)
	  end
    else
	  er("Function expected")
    end
  else
    er("String expected")
  end
end
local run = function(name)
  if type(name) == "string" then
    if process[name] then
	  if coroutine.status(process[name]["Pr"]) == "suspended" then
	    coroutine.resume(process[name]["Pr"])
	    term = process[name]["Di"]
	  else
	    er("Process is "..coroutine.status(process[name]["Pr"])) 
	  end
    else
	  er("Process doesn't exist")
    end
  else
    er("String expected")
  end
end
local hello = function()
  shell.run("hello")
end
new("hi", hello)
run("hi")
GopherAtl #2
Posted 06 March 2015 - 01:19 PM
you forgot to pass new a dVa argument, and new doesn't display an error when that inner-most "if type(dVa)=="table" conditional fails.
Edited on 06 March 2015 - 12:23 PM
CoderPuppy #3
Posted 06 March 2015 - 01:21 PM
You're not passing a third argument to new.
Edit: ninja'd
Edited on 06 March 2015 - 12:22 PM
cdel #4
Posted 06 March 2015 - 01:27 PM
oh right, I forgot to add data for a new feature… *facepalm*. Thanks :)/>