This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mememan000's profile picture

Some Small Problems

Started by mememan000, 24 February 2012 - 07:51 PM
mememan000 #1
Posted 24 February 2012 - 08:51 PM
Hi I've been trying to make a couple of scripts using my 1 day of lua knowledge lol.
I can't FOR THE LIFE OF ME figure out why it won't work.


term.clear()
term.setCursorPos(1,1)

password = "qwerty"
write("Enter your password: ")
input = read()

term.clear()
term.setCursorPos(1,1)

if input == password then
  print("Password correct. Door opening...")
  sleep(1)
  rs.setOutput("right",true)
  sleep(2)
  rs.setOutput("right",false)
  os.shutdown()
else
  print("Password incorrect. !!Alarm sounded!!")
  rs.setOutput("left",true)
  sleep(0.1)
  rs.setOutput("left",false)
  sleep(2)
  os.shutdown
end

The error i am getting says
[string "disk/startup"]:25: '=' expected

This puzzles me because line 25 just says end, how can it be expecting a =?

i also had another code that i was having problems with


term.clear()
term.setCursorPos(1,1)

rednet.open( "top" )

while true do
  event, id, message = os.pullEvent()

  if event == "rednet_message" then
	if id == 8 then
	  print("!!!ALERT!!!")
	  print(message)
	  print()
	end
  end

  getInput( "left" ) = reset
  if reset = 1 then
	term.clear
  end
end

the error i am getting is
[string "startup"]:17: unexpected symbol
i also have another version that does not check the id and it works fine. the purpose of this code is to have a "news" broadcast system and the check for id part is to prevent people from sending a broadcast to people running this code with an unauthorized computer.


thanks :)/>/>
bepZ #2
Posted 24 February 2012 - 08:54 PM
In the first script you forgot the () at the last os.shutdown

and in the 2nd script i cant see where you defined reset
mememan000 #3
Posted 24 February 2012 - 11:19 PM
thanks the first one works but what do you mean by defining reset?
Casper7526 #4
Posted 24 February 2012 - 11:22 PM
Defining a variable means giving it a starting allocation.

reset = 0
reset = ""
reset = false

That way if you accidently try to use the variable in your code before it's givin a proper number/string/true false, it will have one by default to fall back on
MysticT #5
Posted 24 February 2012 - 11:38 PM
2nd script:
line 17:
getInput( "left" ) = reset
should be:
getInput( "left" ) == reset

line 18:
if reset = 1 then
should be:
if reset == 1 then

You forgot a = sign in both lines.
Also you should do what casper says and define the variable with a value before using it, just in case :)/>/>