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

What!? Second Function not firing!

Started by Jman, 11 February 2014 - 04:30 PM
Jman #1
Posted 11 February 2014 - 05:30 PM
Of all the problems in the world. This is by far the one problem I had never expected to encounter.
So when I run this line of code on my advanced computer on my sever.
function on()
  rs.setOutput("back", true)
  term.clear()
  term.setCursorPos(1,1)
  print[[WARNING! CATOSTROPHIC OVERLOAD!
SHUT DOWN SYSTEM BEFORE MELTDOWN!]]
  print("Phase 1")
  a = true
end
function off()
  rs.setOutput("back", false)
  term.clear()
  term.setCursorPos(1,1)
  print[[WANRING! CATASTROPHIC OVERLOAD!
SHUT DOWN SYSTEM BEFORE MELTDOWN!]]
  print("Phase 2")
end
while true do
  on()
  sleep(0.5)
  term.clear()
  print("REPHASE")
  sleep(0.25)
  if a == true then
	off()
	a = false
  else
	print("error...off()")
	break
  end
end
I did not expect I to only half work. especially since I have some nightmare pieces of code ruing on other computers. when I say night mare I men that I have been working on it for so long that I don't know what half of it means only what the outcome is and that it wok everywhere. but I shut them off for now and started coding this simple alarm computer s that I can set off a visual light and sound alarm for when my build craft Kinesis pipes over load I can shut the system down.
Anyways. The code does not return my "endline" function like it was supposed to because it isn't even firing my off() function. I am clueless as to why this is occurring. I am lot and I want to turn on my engines and continue to expand my oil refinery while I transfer liquids to their new silos.
Edited on 11 February 2014 - 04:31 PM
surferpup #2
Posted 11 February 2014 - 06:59 PM
First, you never never declare a, so it never remembers what it was.

I can get it to work by just adding this line immediately after the while:

local a

I see you are using rs.setOutput – but do you know about rs.getOutput?


local a = rs.getOutput("back") -- a will be true (on)  or false (off) depending on state of "back"
Jman #3
Posted 12 February 2014 - 11:44 AM
Yes, however im teaching my friend code and im trying to keep the amount of terms he learns to a minimum. Trying to teach him simplicity before adding new terms.