Jump to content




While Loop Troubles and END Positions

networking computer utility

3 replies to this topic

#1 ChrisStarr

  • Members
  • 5 posts

Posted 29 May 2013 - 10: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


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 May 2013 - 10: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


#3 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 May 2013 - 10: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

#4 ChrisStarr

  • Members
  • 5 posts

Posted 29 May 2013 - 11:03 PM

Thank You for Your Guys Help!
Derp.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users