Jump to content

Computercraft is mysterious


denni000

Recommended Posts

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 :)

Link to comment
Share on other sites

 

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 by Patric20878
Link to comment
Share on other sites

 

^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 by rcmaehl
Link to comment
Share on other sites

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 by Patric20878
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...