Jump to content




need help in programming a computer

computer lua game

  • You cannot reply to this topic
7 replies to this topic

#1 11battlek

  • New Members
  • 4 posts

Posted 03 April 2012 - 02:17 PM

need help in my programming what i want it to do is turn on lights (left) and open a door (right) using password lock then needing another password to open another door all on one computer
this is what i have written

print("systerm online")
term.clear()
term.setCursorPos(1,1)
password = "BattleSeure"
debug ="12345"
pass = "12345"
print ("security systerm")
write ("password required: ")
input = read()
term.clear()
term.setCursorPos(1,1)
if input == password then
print ("access granted")
redstone.setOutput ("right", true)
print ("lights online")
sleep(2)
redstone.setOutput ("left", true)
print ("door open")
sleep (5)
redstone.setOutput("left",false)
print ("Safe security")
write "password required: "
input = read()
if input == passthen
print ("safe access granted")
redstone.setOutput ("back",true)
sleep(2)
redstone.setOutput ("right", false)
os.shutdown()
elseif
input == debug then
exit()
else
print("password incorrect!")
sleep(5)
os.shutdown()
end
this is my first time i used other people programs to make this so not all of it was mine it may be miner issues or rookie mistakes thanks for any help

#2 EatenAlive3

  • New Members
  • 53 posts

Posted 03 April 2012 - 02:40 PM

You should read this: http://www.computerc...faster-read-me/

#3 11battlek

  • New Members
  • 4 posts

Posted 03 April 2012 - 03:00 PM

do u want the error message?
bios:206 [string "startup"]:37: 'end' expected (to close 'if' at line 12)

#4 1v2

  • Members
  • 89 posts
  • LocationAmsterdam

Posted 03 April 2012 - 03:18 PM

I've cleaned it up a bit, that error was because you didn't close the if-statement at line 12.


This should work, but I haven't tested it.

local funtion clear()
term.clear()
term.setCursorPos(1,1)
end
local password = "BattleSeure"
local pass = "12345"
local debug = "1234"
os.pullEvent = os.pullEventRaw
print("system online")
clear()
print ("security system")
write ("password required: ")
input = read()
clear()
if input == password then
print ("access granted")
rs.setOutput ("right", true)
print ("lights online")
sleep(2)
rs.setOutput ("left", true)
print ("door open")
sleep (5)
rs.setOutput("left",false)
end
print ("Safe security")
write "password required: "
input = read()
if input == pass then
print ("safe access granted")
rs.setOutput ("back",true)
sleep(2)
rs.setOutput ("right", false)
os.shutdown()
elseif
input == debug then
exit()
else
print("password incorrect!")
sleep(5)
os.shutdown()
end


#5 11battlek

  • New Members
  • 4 posts

Posted 03 April 2012 - 04:18 PM

no doesn't work error bios:206: [string "startup"]:6: unfinished string

#6 11battlek

  • New Members
  • 4 posts

Posted 03 April 2012 - 04:53 PM

View Post1v2l3a4m5e6n, on 03 April 2012 - 03:18 PM, said:

I've cleaned it up a bit, that error was because you didn't close the if-statement at line 12.


This should work, but I haven't tested it.

local funtion clear()
term.clear()
term.setCursorPos(1,1)
end
local password = "BattleSeure"
local pass = "12345"
local debug = "1234"
os.pullEvent = os.pullEventRaw
print("system online")
clear()
print ("security system")
write ("password required: ")
input = read()
clear()
if input == password then
print ("access granted")
rs.setOutput ("right", true)
print ("lights online")
sleep(2)
rs.setOutput ("left", true)
print ("door open")
sleep (5)
rs.setOutput("left",false)
end
print ("Safe security")
write "password required: "
input = read()
if input == pass then
print ("safe access granted")
rs.setOutput ("back",true)
sleep(2)
rs.setOutput ("right", false)
os.shutdown()
elseif
input == debug then
exit()
else
print("password incorrect!")
sleep(5)
os.shutdown()
end
no doesn't work error bios:206: [string "startup"]:6: unfinished string

#7 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 03 April 2012 - 07:18 PM

I'll point out the line causing the issue. See if you can spot what is wrong.

local funtion clear()


#8 virtualayu

  • New Members
  • 31 posts

Posted 08 April 2012 - 02:58 AM

function not funtion
and maybe i'm wrong but i think you can't create a function named clear() , i'm not sure...
anyway it'll be better to name it clearScreen() or something like that but it's just for an easy reading of your code...

and i really don't understand why you use local term to declare a function or a variable.... your program is so small... you don't need it... and declaring local vars is only if you declare it inside a function... (maybe i'm wrong?) declaring a variable like you did is useless because it will be declare as a global one anyway... (aigain i'm maybe wrong... XD)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users