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

Why does this go wrong

Started by mb55177, 07 April 2014 - 06:18 PM
mb55177 #1
Posted 07 April 2014 - 08:18 PM
Hey everybody out there
I am not new with computercraft as I have been with it since the good old days of tekkit but I haven't actually done much programming on the computers and now I am trying to implement a new ID system for a bank setup I am making.
this is the code



term.setCursorPos(1,1)
print("Please Input ID#")
input = os.pullEvent("char")
if input == ("1") then
ID#1()
elseif input == ("2") then
ID#2()
elseif input == ("3") then
ID#3()
else
print("Please Re-enter Your ID#")
sleep(1)
end
end

function ID#1()
print("Accessing Account Info")
term.clear()
term.setCursorPos(1,1)
print("Hello MB55177")
term.setCursorPos(6,1)
print("Your Account is as follows…")
term.setCursorPos(8,2)
print("Maximum Security Level")
term.setCursorPos(9,3)
print("Crafting Enabled")
end

function Id#2()
print("please contact your system administrator")
sleep(2)
shutdown()
end

function Id#3()
print("please contact your system administrator")
sleep(2)
shutdown()
end



this is as far as I have gotten but every time I try to run it, it just errors : "bios:339: [string "id-system3"]:8: '=' expected"
but I cannot work out what I have done wrong

HELP???




edit: I found that by taking away the #'s in the function name's solved the problem, I then cleaned up the code a bit an after that I thought it was working but it then came up with a different error which I am now working through. here is the new code and the problem
Problem: "bios:339: [string "id-system4"]:5: '' expected"
and the code:
"id
id=function ()
while true do
term.clear()
term.setCursorPos(1,1)
print("Please Input ID#")
r = os.pullEvent("char")
if r == ("1") then
Identification1()
elseif r == ("2") then
Identification2()
elseif r == ("3") then
Identification3()
else
print("Please enter Your ID#")
end
end

function Identification1()
while true do
print("Accessing Account Info")
term.clear()
term.setCursorPos(1,1)
print("Hello MB55177")
term.setCursorPos(6,1)
print("Your Account is as follows…")
term.setCursorPos(8,2)
print("Maximum Security Level")
term.setCursorPos(9,3)
print("Crafting Enabled")
sleep(3)
end
end

function Identification2()
while true do
Print("please contact system administrator")
sleep(2)
shutdown()
end
end

function Identification3()
while true do
Print("please contact you system administrator")
sleep(2)
shutdown()
end
end

end"
and id#1 is still the only one which works
Edited on 08 April 2014 - 05:09 PM
LittleBlackA #2
Posted 07 April 2014 - 11:36 PM
ID#3()
else
print("Please Re-enter Your ID#")
sleep(1)
end
end

I think, repeat think that somewhere in there is the issue but I am not the best at computer craft so dont take my word for it, I will try to fix it up than tell you if it worked :D/>
Bomb Bloke #3
Posted 07 April 2014 - 11:40 PM
Hash symbols may not be used within variable / function names.
LittleBlackA #4
Posted 07 April 2014 - 11:45 PM
^ Oh i trhought you would have to do some greater then string under variable ID#3
Like this…
ID#3()
elseif input => ("3") then –Greater than 3 goto next step which is below
print("Please Re-enter Your ID#")
sleep(1)
end
end
But as I said I am new to LUA so dont take my word for it :/
LoneRangerGuy #5
Posted 08 April 2014 - 12:12 AM
I'm not a lua expert and I'm not sure if this is your issue but I would avoid using any special characters in names. From the 5.1 manual: "Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit." So a good start may be to change the names that include the pound sign "#" to an underscore or just eliminate it.
mb55177 #6
Posted 08 April 2014 - 05:00 AM
LittleBlackA - thanks i'll try that but it was not the error

LonRangerGuy + Bomb Bloke - thanks, I figured it out myself but if I hadn't it would have been really useful inormation
Edited on 08 April 2014 - 03:18 AM
mb55177 #7
Posted 08 April 2014 - 08:17 PM
Hello everybody who has looked at this post, I am now announcing my code is working!!! here is the pastebin : http://pastebin.com/efNXpnd3 you can add in the variables fro the different id's from 1-9 (+0 of course) and it will bring up your different account details. as of this moment the only ones coded in are id's 1-3 and the only one with "account info" in it is id1