Jump to content




Then is there, but it still gives me errors


9 replies to this topic

#1 xbeigeninjax

  • Members
  • 4 posts

Posted 26 January 2013 - 12:40 PM

Here is my code:
-- This is the RedSole CC program by xbeigeninjax

write("Welcome to RedSole! Home|RA|Exit|Help: ")
if input = "RA" then do redstoneAct()
if input = "exit" then do exit()
if input = "help" then do help()
end
function welcomeS()
  write("Welcome to RedSole! Home|RA|ExitHelp: ")
    if input = "RA" then do redstoneAct()
    if input = "exit" then do exit()
    if input = "help" then do help()
function redstoneTrue()
write("Which side do you want?(L for left, S for stern, B for bottom, etc.)")
input == read()
if input = "Home" then do welcomeS()
if input = "Exit" then do exit()
if input = "Help" then do help()
if input = "L" 
write("For how long?(inf for infinite)")
if input = "inf" do redstone.setOutput("left",true)
else input = x do redstone.setOutput("left",true) sleep(x)
if input = "R" 
write("For how long?(inf for infinite)")
if input = "inf" do redstone.setOutput("right",true)
else input = x do redstone.setOutput("right",true) sleep(x)
if input = "B" 
write("For how long?(inf for infinite)")
if input = "inf" do redstone.setOutput("bottom",true)
else input = x do redstone.setOutput("bottom",true) sleep(x)
if input = "S" 
write("For how long?(inf for infinite)")
if input = "inf" do redstone.setOutput("back",true)
else input = x do redstone.setOutput("back",true) sleep(x)
if input = "T" 
write("For how long?(inf for infinite)")
if input = "inf" do redstone.setOutput("top",true)
else input = x do redstone.setOutput("top",true) sleep(x)
function redstoneAct()
write("Type T for true and F for false (redstone activation): ")
input == read()
if input = "T" do redstoneTrue()
if input = "F" write("Which side do you want off? (A for all): ")
if input = "Home" do welcomeS()
if input = "Exit" do exit()
if input = "Help" do help()
if input = "A" do redstone.setOutput(false)
if input = "B" do redstone.setOutput("bottom",false)
if input = "L" do redstone.setOutput("left",false)
if input = "R" do redstone.setOutput("right",false)
if input = "S" do redstone.setOutput("back",false)
if input = "T" do redstone.setOutput("top",false)
end
end
-- This is the help section of the code.
function help()
print("Okay, so you need help. But since I am a computer and I only understand Lua, I can only tell you what I think you might ask.") sleep(7)
print("So, first of all, in the welcome screen you can type Home to do nothing(because you're already there), RA for the actual console,") sleep(7)
print("Help to get here, and Exit to exit the program. Once you are in RA, you have a choice of T if you want to activate redstone, or") sleep(7)
print("F if you want to turn off redstone. Both inputs direct you to a panel where you input the side you want the redstone to come out of.") sleep(7)
print("From there (if you chose T), you can choose the duration of the redstone output, and it can be any number, including infinity.") sleep(7)
print("And at any point in the program that you can input a variable, you can input any of the welcome screen options (except in the one your in).") sleep(7)
write("Help Done. Input any welcome option: ")
input == read()
if input = "home" do welcomeS()
if input = "RA" do redstoneAct()
if input = "exit" do exit()
end
end
It says "then expected" in line 4, but I have one there (probably in the wrong place), and probably a world of other errors hidden in there. If you would be so kind as to tell me what is wrong and give me a snippet of the line of code wrong back, I would appreciate it.

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 26 January 2013 - 01:38 PM

if statements use == for equality not = change all the = in the if's to == and u will be good.

Also please use [code][/code] tags to format code nicely.

EDIT: also there is a LARGE lack of end's to the if's. also those do's are wrong.

EDIT #2: input == read() should be input = read() you have your thinking about equals and assignments the wrong way around, = means put this in this variable, == is an equality check

Edited by TheOriginalBIT, 26 January 2013 - 03:58 PM.


#3 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 26 January 2013 - 03:44 PM

you also probably want to use elseif when you have more than one if statement. Example:

if input == "home" then
  welcomeS()
elseif input == "RA" then
  redstoneAct()
elseif input == "exit" then
  exit()
end

Same thing for all of your if's and the else's with a condition after them in the rest of your code.

--Edit fixed my own dam typos.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 26 January 2013 - 03:54 PM

View Postcrazyguymgd, on 26 January 2013 - 03:44 PM, said:

you also probably want to use elseif when you have more than one if statement. Example:

if input == "home" do
  welcomeS()
elseif input == "RA" do
  redstoneAct()
elseif input == "exit" do
  exit()
end

Same thing for all of your if's and the else's with a condition after them in the rest of your code.
You might want to fix your own bugs here

if ... do ? o.O I think you mean if ... then

#5 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 26 January 2013 - 04:01 PM

View PostTheOriginalBIT, on 26 January 2013 - 03:54 PM, said:

View Postcrazyguymgd, on 26 January 2013 - 03:44 PM, said:

you also probably want to use elseif when you have more than one if statement. Example:

if input == "home" do
  welcomeS()
elseif input == "RA" do
  redstoneAct()
elseif input == "exit" do
  exit()
end

Same thing for all of your if's and the else's with a condition after them in the rest of your code.
You might want to fix your own bugs here

if ... do ? o.O I think you mean if ... then

Dam thanks for the catch. My point still stands though, use ifelse!

#6 xbeigeninjax

  • Members
  • 4 posts

Posted 26 January 2013 - 05:13 PM

View PostTheOriginalBIT, on 26 January 2013 - 01:38 PM, said:

if statements use == for equality not = change all the = in the if's to == and u will be good.

Also please use [code][/code] tags to format code nicely.

EDIT: also there is a LARGE lack of end's to the if's. also those do's are wrong.

EDIT #2: input == read() should be input = read() you have your thinking about equals and assignments the wrong way around, = means put this in this variable, == is an equality check

Ok, first, how do I edit the original post? And so I need to get rid of all the "do"s? And how many ends do I need (sorry for being a noob, I am just learning Lua)?

Nvm I figured out how to change the post.

Edited by xbeigeninjax, 26 January 2013 - 05:19 PM.


#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 26 January 2013 - 05:33 PM

You need an end at the end of each block. Where a block starts with an if, while, function, contains instructions to perform. After these instructions is where the end goes.

EDIT: yes get rid of the do's an if statement is if .<condition> then a while statement is while <condition> do


#8 xbeigeninjax

  • Members
  • 4 posts

Posted 26 January 2013 - 06:54 PM

View PostTheOriginalBIT, on 26 January 2013 - 05:33 PM, said:

You need an end at the end of each block. Where a block starts with an if, while, function, contains instructions to perform. After these instructions is where the end goes.

EDIT: yes get rid of the do's an if statement is if .<condition> then a while statement is while <condition> do

I have gotten everything to work up to line 33, where it needs another "then" somewhere. Here is the somewhat fixed code:
-- This is the RedSole CC program by xbeigeninjax

write("Welcome to RedSole! Home|RA|Exit|Help: ")
  input = read()
if input == "RA" then redstoneAct()
elseif input == "exit" then exit()
elseif input == "help" then help()
end
function welcomeS()
  input = read()
  write("Welcome to RedSole! Home|RA|ExitHelp: ")
    if input == "RA" then redstoneAct()
    elseif input == "exit" then exit()
    elseif input == "help" then help()
end
function redstoneTrue()
write("Which side do you want?(L for left, S for stern, B for bottom, etc.)")
input = read()
if input == "Home" then welcomeS()
  elseif input == "Exit" then exit()
elseif input == "Help" then help()
elseif input == "L" then redstone.setOutput("left",true) redstoneLth()
  elseif input == "R" then redstone.setOutput("right",true) redstoneLth()
  elseif input == "S" then redstone.setOutput("back",true) redstoneLth()
  elseif input == "T" then redstone.setOutput("top",true) redstoneLth()
  elseif input == "B" then redstone.setOutput("bottom",true) redstoneLth()
end
function redstoneLth()
    write("For how long? (inf for infinite): ")
      input = read()
      input = x
      if x == "inf"
      if x ~= "inf" then sleep(x)
end   
function redstoneAct()
write("Type T for true and F for false (redstone activation): ")
input = read()
if input == "T" do redstoneTrue()
elseif input == "F" write("Which side do you want off? (A for all): ")
elseif input == "Home" do welcomeS()
elseif input == "Exit" do exit()
elseif input == "Help" do help()
elseif input == "A" do redstone.setOutput(false)
elseif input == "B" do redstone.setOutput("bottom",false)
elseif input == "L" do redstone.setOutput("left",false)
elseif input == "R" do redstone.setOutput("right",false)
elseif input == "S" do redstone.setOutput("back",false)
elseif input == "T" do redstone.setOutput("top",false)
end
end
-- This is the help section of the code.
function help()
print("Okay, so you need help. But since I am a computer and I only understand Lua, I can only tell you what I think you might ask.") sleep(7)
print("So, first of all, in the welcome screen you can type Home to do nothing(because you're already there), RA for the actual console,") sleep(7)
print("Help to get here, and Exit to exit the program. Once you are in RA, you have a choice of T if you want to activate redstone, or") sleep(7)
print("F if you want to turn off redstone. Both inputs direct you to a panel where you input the side you want the redstone to come out of.") sleep(7)
print("From there (if you chose T), you can choose the duration of the redstone output, and it can be any number, including infinity.") sleep(7)
print("And at any point in the program that you can input a variable, you can input any of the welcome screen options (except in the one your in).") sleep(7)
write("Help Done. Input any welcome option: ")
input == read()
if input = "home" do welcomeS()
if input = "RA" do redstoneAct()
if input = "exit" do exit()
end
end


#9 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 26 January 2013 - 08:21 PM

You had a lot of missing ends for the ending of functions...

try this,

Spoiler


#10 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 26 January 2013 - 08:54 PM

alternatively you can also do something like this. I have written comments on each line to help you understand why things are being done the way I did them, also this system can easily be expanded, see the comments on how to expand to add more options.

Spoiler






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users