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

[LUA] Help With Creating A Database

Started by BabyCodder, 01 April 2013 - 02:10 AM
BabyCodder #1
Posted 01 April 2013 - 04:10 AM
I am currently coding a rednet message receiving system. I need something that saves (The save function) the message as a number or in a table and i need to print when I click on the monitor displaying this. Currently i have a sleep(5) and then do the print code but eventually this will be controlled by a os.pullEvent("screen_touch") Also I wondered how I can do all this but at the same time run a piece of code that checks for the screen_touch. Any help is appreciated. My current code is posted bellow.


d = 0
z = 1
i = 1
x = 0
rednet.open("back")
m = peripheral.wrap("top")
function save()
  q =(d+1)
  msg = tonumber(q)
  d =(d+1)
end
function printq()
  m.clear()
  m.setCursorPos(1,1)
  m.write(msg)
end
function message()
  x =(x+1)
  i =(i+2)
  m.setCursorPos(z,i)
  m.write("Sender: "..id)
  save()
  i =(i+1)
  m.setCursorPos(z,i)
  m.write("Message Saved As: "..tonumber(q))
  sleep(5)
  printq()
end

function new()
  m.clear()
  m.setCursorPos(1,1)
  m.write("NEW MESSAGE(S):")
  message()
end
while true do
  id, msg = rednet.receive()
  if x == 0 then
	new()
  elseif x == 6 then
	z = 19
	i = 1
	m.setCursorPos(z,i)
	message()
  else
	message()
  end
end
Dlcruz129 #2
Posted 01 April 2013 - 04:27 AM
You can run two functions at once with parallel. Use parallel.waitForAny(func1, func2)
BabyCodder #3
Posted 01 April 2013 - 04:33 AM
You can run two functions at once with parallel. Use parallel.waitForAny(func1, func2)
Thank you. I'll note that on my 'notes' monitor so I remember to add it.