Jump to content

Recommended Posts

Posted

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

Posted (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 by Patric20878
Posted (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 by rcmaehl
Posted (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 by Patric20878
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...