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

Would someone be willing to take a look?

Started by ajw1899, 11 August 2012 - 06:50 PM
ajw1899 #1
Posted 11 August 2012 - 08:50 PM
Ive been trying to program my computer startup for my nuclear reactor chamber, and it keep getting an error. Would someone be willing to take a look?

while true do
term.clear
term.setCursorPos (1, 1 )
print ("WARNING: REACTOR UNSTABLE. CONTINUE? Y/N)"
if imput = "Y" then
print ("Imput Nuclear Reactor Passcode")
imput = read ("*")
if imput = "Celeron1" then
Print ("Confirmed. 30 Seconds until Reactor Flood")
redstone.setOutput ("left", true)
sleep (30)
redstone.setOutput ("left", false)
end
end
end

After saving the startup and rebooting, I get the following error:
bios:206: [string "startup"] :3: '=' expected

please help! ;)/>/>
Lyqyd #2
Posted 11 August 2012 - 08:53 PM
Well, line three doesn't seem to have an error there, but you do have one later on. Lua is case sensitive, so Print and print are two different things.
toxicwolf #3
Posted 11 August 2012 - 08:56 PM
Perhaps the space between the functions and the parenthesis () is causing the problem? Lua is probably thinking you are trying to set a variable with that name to the value of the stuff in the parenthesis, hence the "= expected".
Just my two cents.
ajw1899 #4
Posted 11 August 2012 - 08:59 PM
Well, line three doesn't seem to have an error there, but you do have one later on. Lua is case sensitive, so Print and print are two different things.

Fixed

Perhaps the space between the functions and the parenthesis () is causing the problem? Lua is probably thinking you are trying to set a variable with that name to the value of the stuff in the parenthesis, hence the "= expected".
Just my two cents.

Also fixed, still recieving the error however :/
toxicwolf #5
Posted 11 August 2012 - 09:05 PM
Line 2 should read:
term.clear()
As soon as the Lua interpreter reached the beginning of line 3, it expected a '=' because you didn't actually call the function, so it thought you were trying to set it's value.
ajw1899 #6
Posted 11 August 2012 - 09:11 PM
Line 2 should read:
term.clear()
As soon as the Lua interpreter reached the beginning of line 3, it expected a '=' because you didn't actually call the function, so it thought you were trying to set it's value.

Awesome, that fixed it :(/>/>
But now im getting [string "startup"] :5: 'then' expected
;)/>/>
toxicwolf #7
Posted 11 August 2012 - 09:13 PM
Line 2 should read:
term.clear()
As soon as the Lua interpreter reached the beginning of line 3, it expected a '=' because you didn't actually call the function, so it thought you were trying to set it's value.

Awesome, that fixed it :(/>/>
But now im getting [string "startup"] :5: 'then' expected
;)/>/>
When querying the value of a variable, use '==' rather than '='.
ajw1899 #8
Posted 11 August 2012 - 09:20 PM
Line 2 should read:
term.clear()
As soon as the Lua interpreter reached the beginning of line 3, it expected a '=' because you didn't actually call the function, so it thought you were trying to set it's value.

Awesome, that fixed it :(/>/>
But now im getting [string "startup"] :5: 'then' expected
:(/>/>
When querying the value of a variable, use '==' rather than '='.

;)/>/> Fixed! Hopefully this is the last error…
"WARNING: REACTOR UNSTABLE CONTINUE? Y/N" flashed on the screen then it says
bios83 too long without yielding
any ideas?
Lyqyd #9
Posted 11 August 2012 - 09:27 PM
Though, you're testing the input (spelled with an M?) without ever getting any input.
ajw1899 #10
Posted 11 August 2012 - 09:35 PM
Though, you're testing the input (spelled with an M?) without ever getting any input.

I added input = read (*) and that stopped the error, but now it wont proceed no matter what I put in
toxicwolf #11
Posted 11 August 2012 - 09:40 PM
There are a couple of problems here. The too long without yielding error occurs because the computer runs through the loop over and over, without pausing to execute some code. I would suggest either removing the loop altogether (it seems unneeded to me) or adding an else conditional to break the loop. Also, you are never actually getting the input from the user.

This is my version of the code (disclaimer: written off of the top of my head):

local input = nil
local passcode = "Celeron1"
local side = "left"

local clear = function() term.clear() term.setCursorPos(1, 1) end

clear()
print("WARNING: REACTOR UNSTABLE. CONTINUE? Y/N")

repeat
    input = string.lower(read())
until input == "y" or input == "n"

if input == "y" then
    clear()
    print("Input Nuclear Reactor Passcode:")
    input = read("*")
    if input == passcode then
        print("Passcode confirmed. 30 seconds until Reactor Flood...")
        redstone.setOutput(side, true)
        sleep(30)
        redstone.setOutput(side, false)
        clear()
        print("Reactor Flooded, shutting down...")
        os.shutdown()
    else
        clear()
        print("Incorrect Passcode, shutting down...")
        os.shutdown()
else
    clear()
    print("Shutting down...")
    os.shutdown()
end
I added a check to only allow Y/N keys to be pressed, whether caps lock is on or not, and I added some shutdowns to close the program nicely when it finishes.
ajw1899 #12
Posted 11 August 2012 - 09:43 PM
There are a couple of problems here. The too long without yielding error occurs because the computer runs through the loop over and over, without pausing to execute some code. I would suggest either removing the loop altogether (it seems unneeded to me) or adding an else conditional to break the loop. Also, you are never actually getting the input from the user.

This is my version of the code (disclaimer: written off of the top of my head):

local input = nil
local passcode = "Celeron1"
local side = "left"

local clear = function() term.clear() term.setCursorPos(1, 1) end

clear()
print("WARNING: REACTOR UNSTABLE. CONTINUE? Y/N")

repeat
	input = string.lower(read())
until input == "y" or input == "n"

if input == "y" then
	clear()
	print("Input Nuclear Reactor Passcode:")
	input = read("*")
	if input == passcode then
		print("Passcode confirmed. 30 seconds until Reactor Flood...")
		redstone.setOutput(side, true)
		sleep(30)
		redstone.setOutput(side, false)
		clear()
		print("Reactor Flooded, shutting down...")
		os.shutdown()
	else
		clear()
		print("Incorrect Passcode, shutting down...")
		os.shutdown()
else
	clear()
	print("Shutting down...")
	os.shutdown()
end
I added a check to only allow Y/N keys to be pressed, whether caps lock is on or not, and I added some shutdowns to close the program nicely when it finishes.


…. i think I love you. Freakign awesome, im gonna try this out, thank you so much!