Jump to content


Dog

Member Since 06 Jan 2014
Offline Last Active Today, 03:38 PM
*****

Posts I've Made

In Topic: passing parameters to running program with read()

25 July 2019 - 06:32 PM

OK, right now the code will exit if you type exit(), but will continue to run and allow you to click the button as often as you like without exiting. How is that different than what you want?

In regard to the button not changing the output more than once - that's because you only ever set 'out' once in the code and never set it again - and you base 'sOut' on 'out' - so neither value changes. I'd recommend making a simple change to your code, like so...

Change this...
  sOut = not out

to this...
rs.setOutput("bottom", not rs.getOutput("bottom"))

and remove...
rs.setOutput("bottom", not sOut)

In Topic: passing parameters to running program with read()

25 July 2019 - 03:30 PM

Please post your code...

In Topic: passing parameters to running program with read()

24 July 2019 - 04:02 PM

I don't see where you tried to use the parallel API, but it's relatively simple to implement with what you've got. First, you need to encapsulate your input routines in functions then use the parallel API to execute both input routines. Something like this...

local function mouseInput()
  while true do --# start an infinite loop
	local _, button, x, y = os.pullEvent("mouse_click")
	if x == 2 and y == 2 then
	  sOut = not out
	end
	rs.setOutput("bottom", sOut)
  end
end

local function exitInput()
  while true do --# start an infinite loop
	term.setCursorPos(1, h - 2)
	term.clearLine()
	term.setCursorPos(1, h - 1)
	term.write("Type exit() to exit")
	term.setCursorPos(1, h)
	if read() == "exit()" then break end --# break the loop when exit() is entered
  end
end

parallel.waitForAny(mouseInput, exitInput)

In Topic: passing parameters to running program with read()

24 July 2019 - 01:11 PM

I think you're over-complicating a relatively simple problem. As SquidDev requested, please post the code you tried with the parallel API - there are reasons why it didn't work for you, but we can't suggest a fix until we see exactly what you tried.

In Topic: Reading and writing files

30 June 2019 - 04:32 PM

Using h.readLine() you could do this...
local myTable = { }
local myFile = fs.open("/myFile", "r")
repeat --# start a loop that ends with a condition
  local line = myFile.readLine()
  if line then --# if the line read is not nil then add it to the table
    myTable[#myTable + 1] = line
  end
until line == nil --# end the loop if the line read is nil
myFile.close()