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

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

Started by Yanniclord, 17 October 2014 - 10:58 PM
Yanniclord #1
Posted 18 October 2014 - 12:58 AM
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.

Spoilerwhile 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 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

Hope anyone can find out whats wrong here. Regards -Yanniclord
valithor #2
Posted 18 October 2014 - 01: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 on 17 October 2014 - 11:43 PM
Yanniclord #3
Posted 18 October 2014 - 11:15 AM
Awesome man thank you very much for the help, i just couldnt find the spot, so really, thank you :)/>