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

forgot to add remote control

Started by SlaaLogic, 15 February 2013 - 09:21 AM
SlaaLogic #1
Posted 15 February 2013 - 10:21 AM
hey, i've been very bussy since i got help here. but i forgot to add a thing so i can remote controled say to the computer i want the pod to go up. i've got great help here last time and i'm so close to finishing this project.
i added a remote reciever on the black line from the bundled cable at the back of the computer.
how in gods name do i include it in my current program so it wil trigger the lines that make the pod go up then down and then stealth again. pls help.


while 1 == 1 do
term.clear()
term.setCursorPos(1, 1)
local input
print("do you want to call the pod?")
print()
print("y/n")
print()
input = read()
string.lower(input)
-- answer to the question: do you want to call the pod
if input == "y" then
  print("the pod is on it's way down")
  for a = 1,12 do   -- pod coming down
  c = colors.combine (c, colors.white)
  rs.setBundledOutput("back", c)
  sleep(0.5)
  c = colors.subtract (c, colors.white)
  rs.setBundledOutput("back", c)
  sleep(0.5)
  end
  sleep(5.0)
  for a = 1,15 do   -- pod going to surface
  c = colors.combine (c, colors.orange)
  rs.setBundledOutput("back", c)
  sleep(0.5)
  c = colors.subtract (c, colors.orange)
  rs.setBundledOutput("back", c)
  sleep(0.5)
  end
  sleep(5.0)
  for a = 1,3 do   -- back to stealth mode
  c = colors.combine (c, colors.white)
  rs.setBundledOutput("back", c)
  sleep(0.5)
  c = colors.subtract (c, colors.white)
  rs.setBundledOutput("back", c)
  sleep(0.5)
  end
elseif input == "n" then
  print("do you want to send the pod up?")
  print()
  print("y/n")
  print()
  input = read()  -- if input = "y" pod goes up
  string.lower(input)
  if input == "y" then
	print("the pod is on its way up")
	for a = 1,3 do   -- pod to surface
	c = colors.combine(c, colors.orange)
	rs.setBundledOutput("back", c)
	sleep(0.5)
	c = colors.subtract(c, colors.orange)
	rs.setBundledOutput("back", c)
	sleep(0.5)
	end
	sleep(5.0)
	for a = 1,15 do   -- pod goes down
	c = colors.combine(c, colors.white)
	rs.setBundledOutput("back", c)
	sleep(0.5)
	c = colors.subtract(c, colors.white)
	rs.setBundledOutput("back", c)
	sleep(0.5)
	end
	sleep(5.0)
	for a = 1,12 do  --  pod goes stealth
	c = colors.combine(c, colors.orange)
	rs.setBundledOutput("back", c)
	sleep(0.5)
	c = colors.subtract(c, colors.orange)
	rs.setBundledOutput("back", c)
	sleep(0.5)
	end
  elseif input == "n" then
	print("okay the pod will stay where it is")
  else
	print("that is not a valid input, please try again")
  end
else
  print("that is not a valid input please try again")
end
end
Lyqyd #2
Posted 15 February 2013 - 11:10 AM
Split into new topic.
SlaaLogic #3
Posted 15 February 2013 - 01:21 PM
well i'm not very clear.
actually the thing i need to know is how i can make the computer check for input from the bundled cable and the screen itself.
cleaning up the code now so i'll be rewriting a lot of it.
but can't find how to let it check 2 things at one time.
hope this makes the question a little bit clearer.
bjornir90 #4
Posted 16 February 2013 - 05:37 AM
Try using the parallel API (look in the wiki)
Lyqyd #5
Posted 16 February 2013 - 06:41 AM
Instead of using read(), you could look for specific key press events for the input. A simple state tracking variable lets you do it all in one loop:


local state = "call"
print("call pod?")
while true do
  event, p1 = os.pullEvent()
  if event == "char" then
    if p1 == "y" then
      if state == "call" then
        --call pod
        print("call pod?")
      elseif state == "up" then
        --send pod up
        state = "call"
        print("call pod?")
      end
    elseif p1 == "n" then
      if state == "call" then
        state = "up"
        print("send up?")
      elseif state == "up" then
        state = "call"
        print("call pod?")
      end
    end
  elseif event == "redstone" then
    if rs.testBundledInput("back", colors.black) then
      --whatever we do here
    end
  end
end

And you definitely don't need the parallel API for something this simple.
SlaaLogic #6
Posted 19 February 2013 - 10:01 AM
it worked with the event thing.
the only thing i dont like about it is that you cant type the whole word : up, down, and reset.
but for now it wil do. hope the project i'm doing is done soon. for as far as it is done i think i am doing a pretie good job as a new coder or however y should say it. XD

thanks guys. you are the best!!!!