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

IC2 reactor controller

Started by brickw1994, 04 June 2012 - 09:39 PM
brickw1994 #1
Posted 04 June 2012 - 11:39 PM
ive been thinking of taking red power out of the equation with my first program.

by taking it out i mean have the computer control the timer with sleep, but im running into a problem. im having bad luck with the if/then statements, it keeps saying <EOF> error , or expecting end at line 2.

the goal is to have 1 input 1 output:
the input will be triggered from a thermal sensor block, and then come into the computer telling it to set the output to the reactor on then wait 45 seconds with sleep. then turn off, else repeat the application

here the script


local cool = "back"
local control = "right"
function cool()
if rs.getInput(cool) then
rs.setOutput(control, true)
sleep(45)
end
else
Cool()
Pinkishu #2
Posted 04 June 2012 - 11:50 PM
the end comes after the code of else

if <condition> then
  <code>
else
  <code>
end
brickw1994 #3
Posted 04 June 2012 - 11:54 PM
okay thank you ill try it
brickw1994 #4
Posted 04 June 2012 - 11:55 PM
still an error
Pinkishu #5
Posted 04 June 2012 - 11:57 PM
Well whats your new code?
brickw1994 #6
Posted 05 June 2012 - 12:01 AM
local cool = "back"
local control = "right"
function cool()
if rs.getInput(cool) then
rs.setOutput(control, true)
sleep(45)
rs.setOuput(control, false)
else
end
Cool()
Pinkishu #7
Posted 05 June 2012 - 12:03 AM
uh well I don't know what exactly you are trying to do there
Looks like you're also trying to recursively call your function which will crash eventually
use timers instead
brickw1994 #8
Posted 05 June 2012 - 12:04 AM
did you read my description on my first post?
Pinkishu #9
Posted 05 June 2012 - 12:06 AM
oh yeah you only need to wait for the redstone event in a while loop then

or not quite sure there.. why "repeat the application"?
brickw1994 #10
Posted 05 June 2012 - 12:13 AM
i repeat it so when it heats up again and the reactor hits 1000 temp. then it does it again
kazagistar #11
Posted 05 June 2012 - 12:57 AM
You should use the code blocks to preserve code formatting when posting your code, it makes it a lot easier to read. The problem with your code is you are missing and "end" at the end. In lua, there are a number of calls that work as brackets. To make things easier, we use indentation to help remember where we are missing an end. Here are some examples:


function callme(parameters)
  <code>
end

for i,j in ipairs(list) do
  <code>
end

while <condition> do
  <code>
end

if <condition> then
  <code>
end

if <condition> then
  <code>
elseif <condition> then
  <code>
else
  <code>
end
If you put any of these inside each other, each must be closed off by an end. Again, indentation helps you keep track of where you were, since you cannot go up an indentation level without using an end statement. For example:

local cool = "back"
local control = "right"
while true do
  if rs.getInput(cool) then
	rs.setOutput(control, true)
	sleep(45)
	rs.setOutput(control, false)
  else
	sleep(1)
  end
end

You will notice that each time I go in a level, I come back out later. In your code, your function and your if statement go in one level, but you only have one end statement, so the lua interpreter hits the end of the file and is still expecting another end, and thus gives an error.

Also, that last example should be a working version of your code. Cheers!
Luanub #12
Posted 05 June 2012 - 05:34 AM
Lua is case sensitive. Your function name is cool but your calling Cool().

Your also using cool as a var and a function name, you can't do both.

Chaning the function name to Cool will fix both issues.
J15t98J #13
Posted 07 June 2012 - 07:18 PM
Try this.


local cool = "back"
local control = "right"
function cool()
  if rs.getInput(cool) then
	rs.setOutput(control, true)
	sleep(45)
	rs.setOuput(control, false)
  end
  cool()
end

Or this.


local cool = "back"
local control = "right"
repeat
  if rs.getInput(cool) then
	rs.setOutput(control, true)
	sleep(45)
	rs.setOuput(control, false)
until false
Dirkus7 #14
Posted 07 June 2012 - 07:29 PM

local cool = "back"
local control = "right"
while true do
os.pullEvent("redstone")
if rs.getInput(cool) then
rs.setOutput(control, true)
sleep(45)
rs.setOutput(control, false)
end
end
This would be better than constantly checking for input, just wait for it.