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

While Loop Troubles and END Positions

Started by ChrisStarr, 29 May 2013 - 09:25 PM
ChrisStarr #1
Posted 29 May 2013 - 11:25 PM
So I decided to create a program for my indoor security system. What this program is supposed to do
was to use many computers under my house floor waiting for a redstone signal on top. They're pressure plates on top of every computer and when someone steps on it the computer sends a rednet code like for pos 1 it was "1Act" and 2 its was "2Act so on and so fourth to the main computer in my security room connected to a monitor. When the main computer get that "1Act" or "2Act" it highlights it in red on the 3 by 4 advanced monitor. everything works but my "While Loop" and my positions of "End" at the end of every piece of code. Soon this will be much larger than four blocks but I wanted to make sure it worked first!
PLEASE HELP ME!!




rednet.open("bottom")
mon = peripheral.wrap("top")
fPostC = 256
fPosC = 32768
while true do
id, message = rednet.receive()
  if message == ("1Act") then
  mon.setCursorPos(1,1)
  mon.setBackgroundColor(fPosC)
  mon.setTextColor(fPostC)
  mon.write("		 ")
  mon.setCursorPos(1,2)
  mon.write("		 ")
  mon.setCursorPos(1,3)
  mon.write("		 ")
  mon.setCursorPos(1,4)
  mon.write("		 ")
  mon.setCursorPos(1,5)
  mon.write("		 ")
  mon.setCursorPos(1,6)
  mon.write("		 ")
  sleep(0.5)
  mon.clear()
  end

  elseif message == ("2Act") then
  mon.setCursorPos(1,1)
  mon.setBackgroundColor(fPosC)
  mon.setTextColor(fPostC)
  mon.write("		 ")
  mon.setCursorPos(10,2)
  mon.write("		 ")
  mon.setCursorPos(10,3)
  mon.write("		 ")
  mon.setCursorPos(10,4)
  mon.write("		 ")
  mon.setCursorPos(10,5)
  mon.write("		 ")
  mon.setCursorPos(10,6)
  mon.write("		 ")
  sleep(0.5)
  mon.clear()
  end

  elseif message == ("3Act") then
  mon.setCursorPos(1,1)
  mon.setBackgroundColor(fPosC)
  mon.setTextColor(fPostC)
  mon.write("		 ")
  mon.setCursorPos(20,2)
  mon.write("		 ")
  mon.setCursorPos(20,3)
  mon.write("		 ")
  mon.setCursorPos(20,4)
  mon.write("		 ")
  mon.setCursorPos(20,5)
  mon.write("		 ")
  mon.setCursorPos(20,6)
  mon.write("		 ")
  sleep(0.5)
  mon.clear()
  end
  elseif == ("4Act") then
  mon.setCursorPos(30,1)
  mon.setBackgroundColor(fPosC)
  mon.setTextColor(fPostC)
  mon.write("		 ")
  mon.setCursorPos(30,2)
  mon.write("		 ")
  mon.setCursorPos(30,3)
  mon.write("		 ")
  mon.setCursorPos(30,4)
  mon.write("		 ")
  mon.setCursorPos(30,5)
  mon.write("		 ")
  mon.setCursorPos(30,6)
  mon.write("		 ")
  sleep(0.5)
  mon.clear()
  end
end
Bomb Bloke #2
Posted 29 May 2013 - 11:32 PM
If you have ChickenBones's Wireless Redstone mod, I suspect there'd be less server load using redstone transmitters linking to a single computer with a bunch of receivers near it.

You can't use "elseif" after breaking an "if" block with an "end".

For example, this won't work:

if <condition> then
  -- Some code
end

elseif <condition> then
  -- Some more code
end

elseif <condition> then
  -- Yet more code
end

Instead use:

if <condition> then
  -- Some code
elseif <condition> then
  -- Some more code
elseif <condition> then
  -- Yet more code
end
Yevano #3
Posted 29 May 2013 - 11:35 PM
You are putting 'end' after every 'elseif'. You only need the 'end' at the very end of the if … elseif chain.

Edit: ninja'd :P/>
ChrisStarr #4
Posted 30 May 2013 - 12:03 AM
Thank You for Your Guys Help!
Derp.