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

[ERROR] Having a rough start with my first Computercraft program.

Started by Conlan99, 10 January 2013 - 04:48 AM
Conlan99 #1
Posted 10 January 2013 - 05:48 AM
Hello. I have recently become very interested in the computercraft mod. I decided to make an automatic miner using both the redpower and computercraft mods. Although I haven't added the code for the miner's functioning yet, I have added some code to start and stop the program and have a bit of text pop up to help the user. Here is my code so far (Prepare for noobishness):



term.clear()
term.setCursorPos(1,1)

textutils.slowPrint("Hello, and welcome to Conlan99's automatic miner's\nmining program.")
sleep(1)
print("\nThe automatic miner is starting.\nTo stop the automatic miner, please enter Stop.")

local input = read

if (input == stop) or (input == Stop) or (input == exit) or (input == Exit) or (input == quit) or (input == Quit) then
textutils.slowprint("Goodbye.")
sleep(0.25)
os.reboot

else
print("This input is not recognised in this program. Please try again.")

^The program ends here

NOTE: My most recent error said "bios:338: [string "Conlan99Miner"] :15: '=' expected. I have no idea what this means

Please note this is my first post on this forum, let alone any forum, so please, if I messed anything up on the post, please tell me.
ebernerd #2
Posted 10 January 2013 - 05:50 AM
You need to put "end" no quotes at the end of your "os.reboot()" and the end of the program.. :-)
You also need to put empty quotes at the end of "os.reboot" so it is "os.reboot()"
ALSO, where it says "input = read" read needs empty parentheses.
I am not sure, but I dont think you need the parentheses around every available "quit" command. Try it without it. You also need quotation marks around the possible answer.
Conlan99 #3
Posted 10 January 2013 - 05:55 AM
You need to put "end" no quotes at the end of your "os.reboot()" and the end of the program.. :-)
Thanks for the tip, but my program still won't start (Same error) :I
ebernerd #4
Posted 10 January 2013 - 05:57 AM
Did you read my updated post? Sorry about that.
Conlan99 #5
Posted 10 January 2013 - 06:00 AM
Did you read my updated post? Sorry about that.
Oh, I missed that. Thanks!
ebernerd #6
Posted 10 January 2013 - 06:01 AM
You're very welcome. If you need any more help, I would gladly help you! Did the program work now?
Conlan99 #7
Posted 10 January 2013 - 06:10 AM
Did you read my updated post? Sorry about that.
Okay, I added empty parenthesis next to os.reboot, and read, I added quotes around every possible exit answer, and ditched the parentheses on them too. I am now met with the error ":16: '<eof>' expected" btw, line 16 is where my "else" statement starts.
ebernerd #8
Posted 10 January 2013 - 06:21 AM
Just as a test, move that program to a floppy, and delete the IF statement, and see if it works. This is just to see if that isnt the problem. I know it says 16, but sometimes it is relating to something earlier in the code…

Are you using "input" as a variable? you coined it as a variable… when you move it to a floppy, take out the word "local" in front of input = read()

OH! Caught something that is really bad. On one of your textutils, you typed "slowprint", not "slowPrint" that is another issue…

I am a newbie as well, but I do knwo some… so try copying it (cp programname disk/programname) *no parentheses… * and remove LOCAL, and the IF statement. If that doesnt work, I will edit it myself, and give you the correct syntax.

yKnow what… let me try and get it to work
ebernerd #9
Posted 10 January 2013 - 06:26 AM
I GOT IT! I accidentally made you put one extra end. Here is the real code:



term.clear()
term.setCursorPos(1,1)

textutils.slowPrint("Hello, and welcome to Conlan99's automatic miner's\nmining program.")
sleep(1)
print("\nThe automatic miner is starting.\nTo stop the automatic miner, please enter Stop.")
input = read()

if input == "stop" or input == "Stop" or input == "exit" or input == "Exit" or input == "quit" or input == "Quit" then
textutils.slowPrint("Goodbye.")
sleep(0.25)
os.reboot()
else
print("Unrecognizable command.")
end
ebernerd #10
Posted 10 January 2013 - 06:28 AM
I updated it… I am dumb sometimes… forgot something that crashed the program… D:
Conlan99 #11
Posted 10 January 2013 - 08:12 AM
I GOT IT! I accidentally made you put one extra end. Here is the real code:



term.clear()
term.setCursorPos(1,1)

textutils.slowPrint("Hello, and welcome to Conlan99's automatic miner's\nmining program.")
sleep(1)
print("\nThe automatic miner is starting.\nTo stop the automatic miner, please enter Stop.")
input = read()

if input == "stop" or input == "Stop" or input == "exit" or input == "Exit" or input == "quit" or input == "Quit" then
textutils.slowPrint("Goodbye.")
sleep(0.25)
os.reboot()
else
print("Unrecognizable command.")
end
Thank you so much! My code is finally working as I intended it to. Now I just need to get the redstone functioning… And again, Thanks for the help :D/>
remiX #12
Posted 10 January 2013 - 08:14 AM
Instead of checking if it's equal to Quit or quit lower the read string

input = string.lower(read())

if input == "exit" or input == "quit" or input == "stop" then

edit: Shouldn't have copied :P/>
Conlan99 #13
Posted 10 January 2013 - 08:42 AM
Instead of checking if it's equal to Quit or quit lower the read string

input = string.lower(read())

if input == "exit" or input == "quit" or input == "stop" then

edit: Shouldn't have copied :P/>
Shouldn't have copied what? O_o
If you are referring to the code, I would love to know how you managed to get yours into a little white box like that.
Conlan99 #14
Posted 10 January 2013 - 08:47 AM
AHA! I found out how to enter the code into this awesome little box. I've been tinkering around with the code; trying to get the redstone portion done, and now I am faced with a whole new error message that I looked up, but didn't understand… Here it is: :21: 'end' expected (to close 'if' at line 18)

term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Hello, and welcome to Conlan99's automatic miner's\nmining program.")
sleep(1)
print("\nThe automatic miner is starting.\nTo stop the automatic miner, please enter Stop.")
repeat
local input = read()
redstone.setOutput("right",true)
sleep(0.25)
redstone.setOutput("right",false)
sleep(1)
redstone.setOutput("back",true)
sleep(0.25)
redstone.setOutput("back",false)
sleep(0.25)
if input ~= "stop" or input ~= "Stop" or input ~= "exit" or input ~= "Exit" or input ~= "quit" or input ~= "Quit" then
print("Unrecognisable command. Please try again.")
until input == "stop" or input == "Stop" or input == "exit" or input == "Exit" or input == "quit" or input == "Quit" then
textutils.slowPrint("Goodbye.")
sleep(0.25)
os.shutdown()
end
crazyguymgd #15
Posted 10 January 2013 - 08:58 AM
AHA! I found out how to enter the code into this awesome little box. I've been tinkering around with the code; trying to get the redstone portion done, and now I am faced with a whole new error message that I looked up, but didn't understand… Here it is: :21: 'end' expected (to close 'if' at line 18)

term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Hello, and welcome to Conlan99's automatic miner's\nmining program.")
sleep(1)
print("\nThe automatic miner is starting.\nTo stop the automatic miner, please enter Stop.")
repeat
local input = read()
redstone.setOutput("right",true)
sleep(0.25)
redstone.setOutput("right",false)
sleep(1)
redstone.setOutput("back",true)
sleep(0.25)
redstone.setOutput("back",false)
sleep(0.25)
if input ~= "stop" or input ~= "Stop" or input ~= "exit" or input ~= "Exit" or input ~= "quit" or input ~= "Quit" then
print("Unrecognisable command. Please try again.")
until input == "stop" or input == "Stop" or input == "exit" or input == "Exit" or input == "quit" or input == "Quit" then
textutils.slowPrint("Goodbye.")
sleep(0.25)
os.shutdown()
end

think you just need an end after print("Unrecognisable command. Please try again.")
Conlan99 #16
Posted 10 January 2013 - 09:06 AM
think you just need an end after print("Unrecognisable command. Please try again.")
Aha! Thanks. You fixed the "end expected" error! Still having issues with an "Unrecognisable character" error on the same line as my "until" statement.
crazyguymgd #17
Posted 10 January 2013 - 09:11 AM
think you just need an end after print("Unrecognisable command. Please try again.")
Aha! Thanks. You fixed the "end expected" error! Still having issues with an "Unrecognisable character" error on the same line as my "until" statement.
change the then to a do will get it to run.
ebernerd #18
Posted 10 January 2013 - 09:14 AM
Hey, Conlan…. I am going to rewrite this program. It might be messy, and you may not like it, but it will work. Even if you dont like it.. I AM DOIN IT ANYWAY!!!
remiX #19
Posted 10 January 2013 - 09:18 AM
Shouldn't have copied what? O_o

Copying the code directly from another user and pasting it causes it to keep the html editing:

[color=#000000][size=2]input [/size][/color][color=#666600][size=2]=[/size][/color][color=#000000][size=2] read[/size][/color][color=#666600][size=2]()[/size][/color]

[color=#000088]if[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"stop"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"Stop"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"exit"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"Exit"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"quit"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"Quit"[/color][color=#000000] [/color][color=#000088]then
Conlan99 #20
Posted 10 January 2013 - 09:20 AM
Hey, Conlan…. I am going to rewrite this program. It might be messy, and you may not like it, but it will work. Even if you dont like it.. I AM DOIN IT ANYWAY!!!
Okay
Conlan99 #21
Posted 10 January 2013 - 09:22 AM
Shouldn't have copied what? O_o

Copying the code directly from another user and pasting it causes it to keep the html editing:

[color=#000000][size=2]input [/size][/color][color=#666600][size=2]=[/size][/color][color=#000000][size=2] read[/size][/color][color=#666600][size=2]()[/size][/color]

[color=#000088]if[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"stop"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"Stop"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"exit"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"Exit"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"quit"[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] input [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"Quit"[/color][color=#000000] [/color][color=#000088]then
Okay. I'll be sure not to copy the code display thingy in the future :P/>
Conlan99 #22
Posted 10 January 2013 - 09:23 AM
Okay. I'll be sure not to copy the code display thingy in the future :P/>
And I literally just did it again :I
Conlan99 #23
Posted 10 January 2013 - 09:26 AM
change the then to a do will get it to run.

Okay, I changed my "then" to a "do". Not sure why you wanted me to do that though. I thought you were supposed to close a "repeat" with an "until"

change the then to a do will get it to run.

Okay, I changed my "then" to a "do". Not sure why you wanted me to do that though. I thought you were supposed to close a "repeat" with an "until"
Oh, and It's telling me it now expected an = sign…
ebernerd #24
Posted 10 January 2013 - 09:30 AM
I also realized… where your INPUT = WHATEVER… needs TWO ==
crazyguymgd #25
Posted 10 January 2013 - 09:30 AM
sorry I should have been more specific. Maybe this will help:



term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Hello, and welcome to Conlan99's automatic miner's\nmining program.")
sleep(1)
print("\nThe automatic miner is starting.\nTo stop the automatic miner, please enter Stop.")
repeat
local input = read()
redstone.setOutput("right",true)
sleep(0.25)
redstone.setOutput("right",false)
sleep(1)
redstone.setOutput("back",true)
sleep(0.25)
redstone.setOutput("back",false)
sleep(0.25)
if input ~= "stop" and input ~= "Stop" and input ~= "exit" and input ~= "Exit" and input ~= "quit" and input ~= "Quit" then
print("Unrecognisable command. Please try again.")
end
until input == "stop" or input == "Stop" or input == "exit" or input == "Exit" or input == "quit" or input == "Quit" do
textutils.slowPrint("Goodbye.")
sleep(0.25)
os.shutdown()
end

Changes from your code:
end to close if statement.
ors in the if changed to ands
do added at the end of the until condition
ebernerd #26
Posted 10 January 2013 - 09:37 AM
Sorry… I cant get it to work.. I tried…! For like an hour!
remiX #27
Posted 10 January 2013 - 10:05 AM
This has to work…

stopped = false

term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Hello, and welcome to Conlan99's automatic miner's\nmining program.")
sleep(1)
print("\nThe automatic miner is starting.\nTo stop the automatic miner, please enter\nStop/Exit or Quit")
while not stopped do
term.setCursorPos(1, 7) term.clearLine() write(" > ")
local input = string.lower(read())
redstone.setOutput("right",true)
sleep(0.25)
redstone.setOutput("right",false)
sleep(1)
redstone.setOutput("back",true)
sleep(0.25)
redstone.setOutput("back",false)
sleep(0.25)
term.setCursorPos(1, 9) term.clearLine()
if input == "quit" or input == "exit" or input == "stop" then
stopped = true
else
print("Unrecognisable command. Please try again.")
end
end

textutils.slowPrint("Goodbye.")
sleep(1.25)
os.shutdown()