denni000 Posted February 12, 2014 Posted February 12, 2014 Hey guys, I wanted to build a evelator, which i can controll with a computer, but I got really fast problems ^^ My main idea was that, if i write "1" or "2" the redstoneOutput goes left or right, but if i edit my startup there is a error. Would be nice if someone find my mistake ^^ My error: bios:206. [string "startup"]:4: `then` expected -> edit startup write("Pls enter your stage which you want to visit:") local = read() if eingabe = "1" then redstone,setOutput("left", true) sleep(3) os.shutdown() if eingabe = "2" then redsonte,setOutput("right", true) sleep(3) os.shutdown() end I know my english isn`t the best but I think you cant understand me ) Denni000 Unehydrodyday 1 Quote
rcmaehl Posted February 14, 2014 Posted February 14, 2014 (edited) Edit: See two posts down. Edited February 15, 2014 by rcmaehl Quote
Patric20878 Posted February 15, 2014 Posted February 15, 2014 (edited) Try this: write("Pls enter your stage which you want to visit:") local = read() if eingabe =- "1" then redstone,setOutput("left", true) sleep(3) os.shutdown() if eingabe == "2" then redsonte,setOutput("right", true) sleep(3) os.shutdown() end ^What? That "fix" is totally off. There are several things wrong with that code. When you want multiple if's like that, you need to use the if-elseif structure, otherwise you need to end each if statement. Second, you may not use the word "local" as a variable name, as that name is reserved. Third, "=" assigns value, while "==" compares values. And then there's just syntax errors everywhere. If you want to get your programs to work, you're going to have to type a lot better than that, and at least read some programming tutorials online. Here's a fix. write("Please enter which floor you want to visit: ") local eingabe = read() if eingabe == "1" then redstone.setOutput("left", true) sleep(3) os.shutdown() elseif eingabe == "2" then redstone.setOutput("right", true) sleep(3) os.shutdown() end Edited February 15, 2014 by Patric20878 denni000 1 Quote
rcmaehl Posted February 15, 2014 Posted February 15, 2014 (edited) ^What? That "fix" is totally off. There are several things wrong with that code. When you want multiple if's like that, you need to use the if-elseif structure, otherwise you need to end each if statement. Second, you may not use the word "local" as a variable name, as that name is reserved. Third, "=" assigns value, while "==" compares values. And then there's just syntax errors everywhere. If you want to get your programs to work, you're going to have to type a lot better than that, and at least read some programming tutorials online. Here's a fix. write("Please enter which floor you want to visit: ") local eingabe = read() if eingabe == "1" then redstone.setOutput("left", true) sleep(3) os.shutdown() elseif eingabe == "2" then redstone.setOutput("right", true) sleep(3) os.shutdown() end Dude, I just skimmed his code. And was only trying to fix the error that came up. Which I did wrong because my finger was offset. Also, I improved your fix: while true do term.clear() term.setCursorPos(1,1) term.write("Please enter which floor you want to visit: ") local eingabe = read() if eingabe == "1" then redstone.setOutput("left", true) os.sleep(3) os.shutdown() elseif eingabe == "2" then redstone.setOutput("right", true) os.sleep(3) os.shutdown() else term.setCursorPos(1,2) term.write(eingable.." is not a valid floor") os.sleep(3) end end It offers error handling and API calls in case one of the functions (such as sleep) somehow gets overridden. Finally: Link to the wiki since you didn't provide it: http://computercraft.info/wiki Edited February 15, 2014 by rcmaehl denni000 1 Quote
Patric20878 Posted February 16, 2014 Posted February 16, 2014 (edited) Just needed to fix the errors, not add features. Are you trying to write the code for him or are you trying to fix the errors now? Also, googling for the wiki link takes 2 seconds, and learning about it is better done through learning Lua and programming in general. Either way, you fixed none of the 4 or so types of errors, so I did it instead. Did I also mention, os.sleep() is a totally redundant function that just calls sleep()? Overriden, lol. Edited February 16, 2014 by Patric20878 Quote
rcmaehl Posted February 16, 2014 Posted February 16, 2014 Just needed to fix the errors, not add features. Are you trying to write the code for him or are you trying to fix the errors now? Also, googling for the wiki link takes 2 seconds, and learning about it is better done through learning Lua and programming in general. Either way, you fixed none of the 4 or so types of errors, so I did it instead. Did I also mention, os.sleep() is a totally redundant function that just calls sleep()? Overriden, lol. You'd be surprised how many people are too lazy to google. Also, I only attempted to fix the error he was having problems with. Quote
Patric20878 Posted February 17, 2014 Posted February 17, 2014 Well, intentions aside, it's fixed, so that's that. rcmaehl 1 Quote
denni000 Posted February 17, 2014 Author Posted February 17, 2014 okay thanks guys It works now also i googled a bit too.. google knows really everything ^^ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.