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

Lua spitting out random numbers?!

Started by ftank12, 13 January 2013 - 06:08 PM
ftank12 #1
Posted 13 January 2013 - 07:08 PM
Hi there, I have this program, however whenever i try and run it, it spits out random numbers?

I have no idea why! The login seems to work, but the rest dosn't run, and then lua spits out random numbers, which is why i have put the login as a note.

Any help is much appreactiated. :)/>




-- {{

x = 7

function applelogin()

term.clear()
term.setCursorPos(1,1)
print("Apple (Staff Computer)")
print("V1.2.1")
term.setCursorPos(1,17)
print("Login..")
--

term.setCursorPos(7,5)
print("------------------------------------")
term.setCursorPos(7,6)
print("|								  |")
term.setCursorPos(7,7)
print("|	  Logging on? Enter your	  |")
term.setCursorPos(7,8)
print("|	  staff username bellow!	  |")
term.setCursorPos(7,9)
print("|								  |")
term.setCursorPos(7,10)
print("------------------------------------")

		staffnumberinput = read()
		rednet.open("right")
		rednet.send(x, staffnumberinput)
		id, msg = rednet.receive(5)
		rednet.close("right")

		if (id == x) then
term.clear()
term.setCursorPos(1,1)
print("Apple (Staff Computer)")
print("V1.2.1")
term.setCursorPos(1,17)
print("Login..")
--

term.setCursorPos(7,5)
print("------------------------------------")
term.setCursorPos(7,6)
print("|								  |")
term.setCursorPos(7,7)
print("|	   Enter Your Password:	   |")
term.setCursorPos(7,8)
print("|								  |")
term.setCursorPos(7,9)
print("------------------------------------")

staffpassinput = read("*")

if staffpassinput == msg then
print("Welcome "..staffnumberinput.."!")
sleep(2)
else
print("Sorry, that was incorrect!")
sleep(2)
applelogin()
end
else
print("Sorry, that was incorrect!")
sleep(2)
applelogin()
		end

end

applelogin()

}}


local clear = "clear"
local mbpro = 15
local mbair = 17
local imac = 18
local macmini = 19

term.clear()
term.setCursorPos(1,1)
print("Apple (Genius Help Computer)")
print("V1.2.1")
term.setCursorPos(1,17)
print("Genius (Help)")

--

term.setCursorPos(7,5)
print("------------------------------------")
term.setCursorPos(7,6)
print("|								  |")
term.setCursorPos(7,7)
print("|		Waiting for entry...	  |")
term.setCursorPos(7,8)
print("|	Hold down CTRL-R to logout:   |")
term.setCursorPos(7,9)
print("|								  |")
term.setCursorPos(7,10)
print("------------------------------------")

rednet.open("right")
id, msg = rednet.receive()
rednet.close("right")


if id == mbpro then

rednet.open("right")
rednet.send(id, "Help On the way")
rednet.close("right")

term.clear()
term.setCursorPos(1,1)
print("Apple (Genius Help Computer)")
print("V1.2.1")
term.setCursorPos(1,17)
print("Genius (Help)")

--

term.setCursorPos(7,5)
print("------------------------------------")
term.setCursorPos(7,6)
print("|								  |")
term.setCursorPos(7,7)
print("|		 Help needed at:		  |")
term.setCursorPos(7,8)
print("|		 MacBook Pro: 15		  |")
term.setCursorPos(7,9)
print("|	  Type clear to clear:		|")
term.setCursorPos(7,10)
print("------------------------------------")

write(">")
input = read()
if input ~= clear then
print("Hmm, that wasn't one of the options!")
sleep(2)
end

elseif id == mbair then

rednet.open("right")
rednet.send(id, "Help On the way")
rednet.close("right")


term.clear()
term.setCursorPos(1,1)
print("Apple (Genius Help Computer)")
print("V1.2.1")
term.setCursorPos(1,17)
print("Genius (Help)")

--

term.setCursorPos(7,5)
print("------------------------------------")
term.setCursorPos(7,6)
print("|								  |")
term.setCursorPos(7,7)
print("|		 Help needed at:		  |")
term.setCursorPos(7,8)
print("|		 MacBook Air: 17		  |")
term.setCursorPos(7,9)
print("|	  Type clear to clear:		|")
term.setCursorPos(7,10)
print("------------------------------------")


write(">")
input = read()
if input ~= clear then
print("Hmm, that wasn't one of the options!")
sleep(2)
end

elseif id == imac then

rednet.open("right")
rednet.send(id, "Help On the way")
rednet.close("right")


term.clear()
term.setCursorPos(1,1)
print("Apple (Genius Help Computer)")
print("V1.2.1")
term.setCursorPos(1,17)
print("Genius (Help)")

--

term.setCursorPos(7,5)
print("------------------------------------")
term.setCursorPos(7,6)
print("|								  |")
term.setCursorPos(7,7)
print("|		 Help needed at:		  |")
term.setCursorPos(7,8)
print("|			iMac: 18			  |")
term.setCursorPos(7,9)
print("|	  Type clear to clear:		|")
term.setCursorPos(7,10)
print("------------------------------------")


write(">")
input = read()
if input ~= clear then
print("Hmm, that wasn't one of the options!")
sleep(2)
end

elseif id == macmini then

rednet.open("right")
rednet.send(id, "Help On the way")
rednet.close("right")


term.clear()
term.setCursorPos(1,1)
print("Apple (Genius Help Computer)")
print("V1.2.1")
term.setCursorPos(1,17)
print("Genius (Help)")

--

term.setCursorPos(7,5)
print("------------------------------------")
term.setCursorPos(7,6)
print("|								  |")
term.setCursorPos(7,7)
print("|		 Help needed at:		  |")
term.setCursorPos(7,8)
print("|		   MacMini: 19			|")
term.setCursorPos(7,9)
print("|	  Type clear to clear:		|")
term.setCursorPos(7,10)
print("------------------------------------")


write(">")
input = read()
if input ~= clear then
print("Hmm, that wasn't one of the options!")
sleep(2)
end

end
end


Luanub #2
Posted 13 January 2013 - 07:57 PM
You got errors in your if blocks in multiple places.

An if statements must have 1 if and only 1 end. You can have as many elseif's as you want but can only have you else and it must be the last portion of the block.

Example if statement.

if a == b then
  --do some stuff
elseif a == c then
  --do other stuff
else
  --nothing else matched so do this
end

EDIT: the }} is probably causing issues as well. What are you trying to do with them? Are you trying to comment out that entire block? if so try using [[ ]] instead.
Edited on 13 January 2013 - 07:01 PM
ftank12 #3
Posted 13 January 2013 - 09:56 PM
But those secondary if blocks are within that if and then they end that if. So, like an If within an if, unless Lau dosnt understand that, but I've even doing that for ages, so I can't understand why it's giving me errors now?!

EDIT: DERP! I think I had one too many ends, but that still dson't explain why it was giving me random numbers… Hmm, odd. But thanks for the help. It's always a great thought that if I get stuck, I can come here for support.

Thanks again!
Edited on 13 January 2013 - 09:55 PM
RunasSudo-AWOLindefinitely #4
Posted 14 January 2013 - 01:08 PM
If you want people to stop being confused, use indentation.

No indentation (horrible):

if a then
while b == false do
local c = dosomethingelse()
repeat
c = dosomethingelse()
until c == false
end
end

With indentation:

if a then
  while b == false do
    local c = dosomethingelse()
    repeat
      c = dosomethingelse()
    until c == false
  end
end

It will also make it easier to spot missing/too many "ends".
theoriginalbit #5
Posted 14 January 2013 - 01:11 PM
If you want people to stop being confused, use indentation.
In addition to this…

Since this forum doesn't preserve indentation when copy/pasting for long code try to use pastebin, it beats the hell out of trying to manually indent it all just for the forums…
Doyle3694 #6
Posted 15 January 2013 - 11:16 AM
And that's why every "pro" loves pastebin