Jump to content




Noob question: "end" expected to close "while"


  • You cannot reply to this topic
2 replies to this topic

#1 Yanniclord

  • Members
  • 39 posts

Posted 17 October 2014 - 11:58 PM

Hi, im new to the forums, but not ComputerCraft, however lets start :)

So to start off im rewriting a script for CC that works with BigReactors, it first was to simply display info about the Reactor on the monitor above the PC, but then i thought i can maybe add two touch buttons to the monitor that let me toggle the state of the reactor with "reactor.setActive(true/false)", however what ever i try to do it tells me to "end" the line, but i tried alot of ends, from one end to five ends and on many different places, so i now need some help, it would be appreciated, thanks in advance.

Spoiler

Hope anyone can find out whats wrong here. Regards -Yanniclord

#2 valithor

  • Members
  • 1,053 posts

Posted 18 October 2014 - 12:37 AM

while true do
  local reactor1 = peripheral.wrap("BigReactors-Reactor_1")
  local mon = peripheral.wrap("top")
  mon.clear()
  -- Begin Reactor 1
  --mon.setCursorPos(1,1)
  --mon.setTextColor(colors.white)
  --mon.write("Reactor #: ")
  --mon.setTextColor(colors.lime)
  --mon.write("1")
  mon.setCursorPos(1,1)
  mon.setTextColor(colors.white)
  mon.write("Active: ")
  mon.setTextColor(colors.lime)
  mon.write(reactor1.getActive())
  mon.setCursorPos(1,2)
  mon.setTextColor(colors.white)
  mon.write("RF/T: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getEnergyProducedLastTick()))
  mon.setCursorPos(1,3)
  mon.setTextColor(colors.white)
  mon.write("Control Rods: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getNumberOfControlRods()))
  mon.setCursorPos(1,4)
  mon.setTextColor(colors.white)
  mon.write("RF Stored: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getEnergyStored()))
  mon.setCursorPos(1,5)
  mon.setTextColor(colors.white)
  mon.write("Casing Heat: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getCasingTemperature()))
  mon.setCursorPos(1,6)
  mon.setTextColor(colors.white)
  mon.write("Fuel Heat: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getFuelTemperature()))
end <------------------------------------------ end goes here
-- End Reactor 1  


function Clicks()
  mon.setCursorPos(1,7)
  print("ON")
  mon.setCursorPos(1,8)
  print("OFF")
end


function Pick()
  while true do
	event,side,x,y = os.pullEvent()
	if event == "monitor_touch" then
	  if x == 1 and y == 7 then
		reactor.setActive(true)
	  elseif x == 1 and y == 8 then
		reactor.setActive(false)
	  end
	end
	sleep(5)
  end
end

By writing code out like this you can see where the code blocks begin and end. This helps keep code organized and also helps you be able to find where there needs to be ends. As you can see you started the program with a while loop, but there is no end that closes it. Where it says "-- end Reactor 1" is where there needs to be a end to close the while loop that started at the beginning of the program. It is good practice to indent each time you start a new block. A block includes any type of loop, if statement, or a function. When reading over it ends should line up vertically with what they end. It might seem like a little more work, but it makes it easier to read and know where ends are suppose to be placed.

Edited by valithor, 18 October 2014 - 12:43 AM.


#3 Yanniclord

  • Members
  • 39 posts

Posted 18 October 2014 - 10:15 AM

Awesome man thank you very much for the help, i just couldnt find the spot, so really, thank you :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users